Mediacodec.configure Fails With Illegalstateexception For 1080p Videos
Solution 1:
Ok, here to answer my own question again:
Firstly, why I can't extract frame with
ExtractMpegFramesTest
after usingMoviePlayer
to display videos:It appears that some devices can't handle 2 instances of
MediaCodec
at the same time for high res videos (>720p in the case of the Galaxy S4 mini) so you have to properly release one instance ofMediaCodec
before starting the other one, something like this:publicvoidreleaseResources() { // release everything we grabbedif (mDecoder != null) { try { mDecoder.stop(); mDecoder.release(); mDecoder = null; } catch (Exception e) { Timber.d("releaseResources(): message %s cause %s", e.getMessage(), e.getCause()); e.printStackTrace(); } } if (mExtractor != null) { try { mExtractor.release(); mExtractor = null; } catch (Exception e) { Timber.d("releaseResources(): message %s cause %s", e.getMessage(), e.getCause()); e.printStackTrace(); } } }
Secondly, why the
MoviePlayer
fails to configure for 1080p videos. In my case, since I start this activity from a media picker activity with aVideoView
for preview which has aMediaPlayer.OnErrorListener()
registered to detect faulty video. The problem is theonError()
callback has some really weird behavior on the Galaxy S4 mini while it work perfectly fine on my development devices. My wild guess thisMediaPlayer.OnErrorListener()
leaves theMediaCodec
in a bad state that cause a lot of headache later on.So the solution is to set a blank
OnErrorListener()
and properly release theVideoView
before doing anything else withMediaCodec
. Something like this:mVideoView.setOnErrorListener(newMediaPlayer.OnErrorListener() { @OverridepublicbooleanonError(MediaPlayer mp, int what, int extra) { returntrue; } }); ..... mVideoView.stopPlayback(); doOtherThingWithMediaCodec();
This explain a lot of weird thing that happen on different devices. I hope this help someone else debug their app.
Post a Comment for "Mediacodec.configure Fails With Illegalstateexception For 1080p Videos"