Closed thuantran closed 9 years ago
The function reset() also resets the surface/surfaceHolder. Setup everything after reset(), or don't call reset(), in playVideo().
BTW: There is a MediaPlayer wrapper named AndroidMediaPlayer in ijk, for the convenience of switching between them.
Thanks it's working now. And yes I knew about AndroidMediaPlayer class, was planning to do it after I manage to fix this issue here.
Also is there anyway to make the logging less verbose. I used mSwMp.setLogEnabled(false); and it's still a lot.
Spoke too soon, I'm running into the same issue (releasing SurfaceHolder is too slow) I had with vitamio when switching between default device MediaPlayer and IjkMediaPlayer object. Any idea?
In any case, I already feel like your library is a better implementation compared to vitamio, so I plan to stick with it. Hopefully I can sort everything out with it.
01-18 14:28:27.708 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_stop()
01-18 14:28:27.708 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_stop()=0
01-18 14:28:27.708 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ IjkMediaPlayer_reset
01-18 14:28:27.708 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ IjkMediaPlayer_release
01-18 14:28:27.708 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_set_android_surface(surface=0x0)
01-18 14:28:27.708 29015-29015/com.vanilla.eventapp D/IJKMEDIA﹕ ffpipeline_set_surface()
01-18 14:28:27.708 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_set_android_surface(surface=0x0)=void
01-18 14:28:27.708 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_shutdown_l()
01-18 14:28:27.708 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ wait for read_tid
01-18 14:28:27.708 29015-29394/com.vanilla.eventapp W/IJKMEDIA﹕ message_loop exit
01-18 14:28:27.721 29015-29415/com.vanilla.eventapp W/art﹕ Native thread exiting without having called DetachCurrentThread (maybe it's going to use a pthread_key_create destructor?): Thread[21,tid=29415,Native,Thread*=0xb3c13400,peer=0x12c790e0,"Thread-1610"]
01-18 14:28:27.744 29015-29396/com.vanilla.eventapp W/art﹕ Native thread exiting without having called DetachCurrentThread (maybe it's going to use a pthread_key_create destructor?): Thread[19,tid=29396,Native,Thread*=0xaf5bd000,peer=0x12c26320,"Thread-1608"]
01-18 14:28:27.745 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ wait for video_refresh_tid
01-18 14:28:27.753 29015-29015/com.vanilla.eventapp E/IJKMEDIA﹕ SDL_Overlay(ffmpeg): overlay_free_l(0xa012a040)
01-18 14:28:27.753 29015-29015/com.vanilla.eventapp E/IJKMEDIA﹕ SDL_Overlay(ffmpeg): overlay_free_l(0xa012a070)
01-18 14:28:27.753 29015-29015/com.vanilla.eventapp E/IJKMEDIA﹕ SDL_Overlay(ffmpeg): overlay_free_l(0xa012a0a0)
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_shutdown_l()=void
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ IjkMediaPlayer_native_setup
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp D/IJKMEDIA﹕ ffpipeline_create_from_android()
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_set_format_callback(0xa34c5875, 0x20046e)
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_set_format_callback()=void
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_android_set_mediacodec_select_callback()
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp D/IJKMEDIA﹕ ffpipeline_set_mediacodec_select_callback
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_android_set_mediacodec_select_callback()=void
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_dec_ref(): ref=0
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_shutdown_l()
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_shutdown_l()=void
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ IjkMediaPlayer_release
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_set_android_surface(surface=0x0)
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp D/IJKMEDIA﹕ ffpipeline_set_surface()
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_set_android_surface(surface=0x0)=void
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_shutdown_l()
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_shutdown_l()=void
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_dec_ref(): ref=0
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_shutdown_l()
01-18 14:28:27.757 29015-29015/com.vanilla.eventapp W/IJKMEDIA﹕ ijkmp_shutdown_l()=void
01-18 14:28:27.761 176-538/? E/BufferQueueProducer? [SurfaceView] connect(P): already connected (cur=2 req=3)
01-18 14:28:27.761 183-881/? E/MediaPlayerService? setVideoSurfaceTexture failed: -22
01-18 14:28:27.761 183-881/? D/NuPlayerDriver? reset(0xb380f400)
01-18 14:28:27.761 183-29443/? D/NuPlayerDriver? notifyResetComplete(0xb380f400)
01-18 14:28:27.762 29015-29015/com.vanilla.eventapp E/EventApp﹕ Error in playVideo
java.lang.IllegalStateException
at android.media.MediaPlayer.prepareAsync(Native Method)
at tv.danmaku.ijk.media.player.AndroidMediaPlayer.prepareAsync(AndroidMediaPlayer.java:108)
at com.vanilla.eventapp.gui.ActivityBasicPlayer.playVideo(ActivityBasicPlayer.java:417)
at com.vanilla.eventapp.gui.ActivityBasicPlayer.createMediaPlayer(ActivityBasicPlayer.java:344)
at com.vanilla.eventapp.gui.ActivityBasicPlayer.onClick(ActivityBasicPlayer.java:106)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
All native log are output through macro ALOG... in ijkutil/android/loghelp.h. Modify it to what you want.
According to the log, you were creating a MediaPlayer before an IjkMediaPlayer is released?
Nah, I have already called released on IjkMediaPlayer object please check my createMediaPlayer method, it calls my destroyMediaPlayer method first then will create a new MediaPlayer object according to previously set mDecoder variable.
The problem here is sometimes, it takes too long for for the surface to get released and I will get this error in this case. I have updated the log in my previous post to include log from the time when I call destroyMediaPlayer in createMediaPlayer. Please check it out.
IjkMediaPlayer is supposed to hold no more surface after IjkMediaPlayer.release() return.
Try getHolder().setFormat(
I tried
private void destroyMediaPlayer() {
if (mMp != null) {
mMp.release();
mMp.setDisplay(null);
mMp = null;
mSurfaceHolder.setFormat(ImageFormat.YV12);
}
}
but it still has the same problem and with surfaceHolder.setFormat() with some format of PixelFormat or ImageFormat, ijkplayer runs into a new issue
01-22 12:57:14.485 29804-30156/com.vanilla.eventapp E/Surface﹕ dequeueBuffer failed (No such device)
01-22 12:57:14.485 29804-30156/com.vanilla.eventapp E/IJKMEDIA﹕ SDL_Android_NativeWindow_display_l: ANativeWindow_lock: failed -19
01-22 12:57:14.536 29804-30156/com.vanilla.eventapp E/Surface﹕ dequeueBuffer failed (No such device)
01-22 12:57:14.536 29804-30156/com.vanilla.eventapp E/IJKMEDIA﹕ SDL_Android_NativeWindow_display_l: ANativeWindow_lock: failed -19
01-22 12:57:14.586 29804-30156/com.vanilla.eventapp E/Surface﹕ dequeueBuffer failed (No such device)
01-22 12:57:14.586 29804-30156/com.vanilla.eventapp E/IJKMEDIA﹕ SDL_Android_NativeWindow_display_l: ANativeWindow_lock: failed -19
01-22 12:57:14.637 29804-30156/com.vanilla.eventapp E/Surface﹕ dequeueBuffer failed (No such device)
01-22 12:57:14.637 29804-30156/com.vanilla.eventapp E/IJKMEDIA﹕ SDL_Android_NativeWindow_display_l: ANativeWindow_lock: failed -19
01-22 12:57:14.675 29804-30156/com.vanilla.eventapp E/Surface﹕ dequeueBuffer failed (No such device)
01-22 12:57:14.675 29804-30156/com.vanilla.eventapp E/IJKMEDIA﹕ SDL_Android_NativeWindow_display_l: ANativeWindow_lock: failed -19
It keeps spewing out this error even though I have closed the video player activity.
No idea for this situation. The point is try to obtain a fresh surface. Maybe you could try remove the whole surfaceView, detach it from the view hierarchy, and create a new SurfaceView.
I tried that, it does work but it messes up my layout because I use SystemUiHider to hide status and navigation buttons and that glitches out if I do what you said. So in the end I couldn't use it after all.
The point is when I destroy and create default MediaPlayer it works ok. It only happens when I switch between default MediaPlayer and IjkMediaPlayer (or vitamio MediaPlayer for that matter), or if I switch between IjkMediaPlayer with and without MediaCodec enabled. You can check the new log using IjkMediaPlayer with MediaCodec enabled below:
01-22 14:18:35.075 5309-5677/com.vanilla.eventapp I/tv.danmaku.ijk.media.player.IjkMediaPlayer﹕ selected codec: OMX.qcom.video.decoder.avc rank=800
01-22 14:18:35.075 5309-5677/com.vanilla.eventapp W/IJKMEDIA﹕ SDL_AMediaCodecJava_createByCodecName
01-22 14:18:35.081 5309-5696/com.vanilla.eventapp I/OMXClient﹕ Using client-side OMX mux.
01-22 14:18:35.243 5309-5677/com.vanilla.eventapp W/IJKMEDIA﹕ SDL_AMediaCodecJava_init
01-22 14:18:35.243 5309-5677/com.vanilla.eventapp W/IJKMEDIA﹕ SDL_AMediaCodecJava_configure_surface
01-22 14:18:35.243 5309-5677/com.vanilla.eventapp E/IJKMEDIA﹕ configure 0x1004ce 0x300426
01-22 14:18:35.244 5309-5695/com.vanilla.eventapp E/MediaCodec﹕ native_window_api_connect returned an error: Invalid argument (-22)
01-22 14:18:35.244 5309-5677/com.vanilla.eventapp E/MediaCodec﹕ configure failed with err 0xffffffea, resetting...
It's likely the same problem considering the -22 error.
So it all comes back to how to reset the surface view or how to remove and add the surface view into my layout without glitching out. I'll keep trying things. If you have anything new about this, please do tell too.
Finally managed to fix it. Instead of mediaPlayer.setDisplay(null) or other mentioned tricks here. I do this:
ViewGroup parent = (ViewGroup) mSurfaceView.getParent();
int index = parent.indexOfChild(mSurfaceView);
parent.removeView(mSurfaceView);
parent.addView(mSurfaceView, index);
in place of creating an entirely new SurfaceView object. That would cause glitch in your UI especially when you use SystemUiHider. The call to parent.removeView(mSurfaceView) here will call surfaceDestroyed where I release the old MediaPlayer object and addView will recreate the SurfaceView calling surfaceCreated where I create a new MediaPlayer object accordingly.
If you have nothing more to add we can consider this issue closed. Thanks for the awesome library.
Hi there,
I'm having this error using IjkMediaPlayer in my app and I have no video during playback only audio.
Before trying Ijk I used vitamio latest version from git and it works but it does have its issue when I try to switch MediaPlayer objects (check my code) due to a bug causing it not to release surface holder correctly.
Tested on both Nexus 5 and 7 (2013) running Lollipop 5.0.1. ijkplayer is compiled with latest sdk 24.0.2 and ndk r10d
Do you have any idea?
I attach the log and source below