static jlong IjkMediaPlayer_getDuration(JNIEnv *env, jobject thiz)
{
jlong retval = 0;
IjkMediaPlayer *mp = jni_get_media_player(env, thiz);
JNI_CHECK_GOTO(mp, env, NULL, "mpjni: getDuration: null mp", LABEL_RETURN);
retval = ijkmp_get_duration(mp);
LABEL_RETURN:
ijkmp_dec_ref_p(&mp);
return retval;
}
long ijkmp_get_duration(IjkMediaPlayer *mp)
{
assert(mp);
pthread_mutex_lock(&mp->mutex);
long retval = ijkmp_get_duration_l(mp);
pthread_mutex_unlock(&mp->mutex);
return retval;
}
static long ijkmp_get_duration_l(IjkMediaPlayer *mp)
{
return ffp_get_duration_l(mp->ffplayer);
}
long ffp_get_duration_l(FFPlayer *ffp)
{
assert(ffp);
VideoState *is = ffp->is;
if (!is || !is->ic)
return 0;
int64_t duration = fftime_to_milliseconds(is->ic->duration);
if (duration < 0)
return 0;
return (long)duration;
}
#define fftime_to_milliseconds(ts) (av_rescale(ts, 1000, AV_TIME_BASE))
网友评论