Android:MediaPlayer.prepareAsync()上的IllegalStateException

时间:2016-04-01 09:57:50

标签: android android-mediaplayer

我在app中使用Android MediaPlayer在/res/raw文件夹中反复显示.mp4文件作为视频背景。当我在三星和它上面测试时,它运行良好Nexus Android 6.0。

相关代码:(已完成的代码可以找到here

private void playIntro(SurfaceTexture surfaceTexture) {
    if (player != null) {
        player.release();
        player = null;
    }

    try {
        player = new MediaPlayer();
        AssetFileDescriptor afd = getResources().openRawResourceFd(R.raw.gpoview);
        player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
        player.setOnPreparedListener(this);
    } catch (IOException e) {
        e.printStackTrace();
    }

    player.setSurface(new Surface(surfaceTexture));

    player.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
        @Override
        public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
            mVideoWidth = width;
            mVideoHeight = height;
            updateTextureViewSize();
        }
    });

    player.prepareAsync();
}

Crashlytics已针对崩溃报告进行了集成,我收到了许多针对以下崩溃的报告:

Fatal Exception: java.lang.IllegalStateException
       at android.media.MediaPlayer.prepareAsync(MediaPlayer.java)
       at io.evercam.androidapp.onboarding.IntroTextureView.playIntro(IntroTextureView.java:141)
       at io.evercam.androidapp.onboarding.IntroTextureView.onSurfaceTextureAvailable(IntroTextureView.java:58)
       at android.view.TextureView.getHardwareLayer(TextureView.java:385)
       at android.view.View.getDisplayList(View.java:13540)
       at android.view.View.getDisplayList(View.java:13617)
       at android.view.View.draw(View.java:14395)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3237)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3074)
       at android.view.View.getDisplayList(View.java:13570)
       at android.view.View.getDisplayList(View.java:13617)
       at android.view.View.draw(View.java:14395)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3237)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3074)
       at android.view.View.getDisplayList(View.java:13570)
       at android.view.View.getDisplayList(View.java:13617)
       at android.view.View.draw(View.java:14395)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3237)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3074)
       at android.view.View.getDisplayList(View.java:13570)
       at android.view.View.getDisplayList(View.java:13617)
       at android.view.View.draw(View.java:14395)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3237)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3074)
       at android.view.View.getDisplayList(View.java:13570)
       at android.view.View.getDisplayList(View.java:13617)
       at android.view.View.draw(View.java:14395)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3237)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3074)
       at android.view.View.getDisplayList(View.java:13570)
       at android.view.View.getDisplayList(View.java:13617)
       at android.view.View.draw(View.java:14395)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3237)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3074)
       at android.view.View.draw(View.java:14684)
       at android.widget.FrameLayout.draw(FrameLayout.java:472)
       at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2474)
       at android.view.View.getDisplayList(View.java:13575)
       at android.view.View.getDisplayList(View.java:13617)
       at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1577)
       at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1451)
       at android.view.ViewRootImpl.draw(ViewRootImpl.java:2551)
       at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2417)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2006)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1063)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5993)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
       at android.view.Choreographer.doCallbacks(Choreographer.java:574)
       at android.view.Choreographer.doFrame(Choreographer.java:544)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5584)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
       at dalvik.system.NativeStart.main(NativeStart.java)

它100%来自Android 4.4.4的三星设备,但我找不到重现它的方法。

有关它为何会发生以及如何解决或进一步调试的任何建议?

非常感谢!

0 个答案:

没有答案