JNIEXPORT jint JNICALL android_media_omxmediaplayer_getCurrentPosition (JNIEnv *env, jobject thiz) { IPlayer* mp = getOMXMediaPlayer(env, thiz); if (mp == NULL ) { PPLOGE("player is null, getVideoHeight failed"); return 0; } int msec; if (0 != mp->getCurrentPosition(&msec)) { PPLOGE("getCurrentPosition failed"); msec = 0; } PPLOGI("getCurrentPosition: %d", msec); return msec; }
JNIEXPORT void android_media_omxmediaplayer_seekTo(JNIEnv *env, jobject thiz, int msec) { IPlayer* mp = getOMXMediaPlayer(env, thiz); if (mp == NULL ) { jniThrowException(env, "java/lang/IllegalStateException", NULL); return; } int playTime = 0; mp->getCurrentPosition(&playTime); int mediaDiff = msec - playTime; // msec mediaDiff = mediaDiff>0 ? mediaDiff : -mediaDiff; if(mediaDiff > 2000) // 2sec { PPLOGD("jni seekTo: %d(msec)", msec); mp->seekTo(msec); PPLOGD("jni seekTo: %d(msec) end", msec); } else { mp->notify(MEDIA_SEEK_COMPLETE, 0, 0); } }