我的活动基本上是一个“媒体”播放器,可以播放某些内容(例如图像,视频,RSS提要等),我使用不同的布局文件。我有一个播放列表,硬件或模拟器编解码器不支持某些视频。因此,当我在尝试加载视频时遇到错误时,我只需移动到下一个并尝试播放它。
问题是我收到加载错误后开始播放下一个媒体。我的videoPlayer布局上的VideoView会抛出一个NPE并崩溃应用程序:S
我使用版本4.1.2,4.2.2,4.3和2.3.3在模拟器上进行了测试。所有4.x.x版本都显示了问题...
以下是试图播放视频的片段。
...
videoView = (VideoView) getActivity().findViewById(R.id.videoview);
videoView.setVideoPath(currentMediaPath);
videoView.setOnErrorListener(new OnErrorListener()
{
@Override
public boolean onError(MediaPlayer player, int what, int extra)
{
String message = "error: [" + currentIndex + "] " + currentMediaPath + " what: " + what + " extra: "
+ extra;
L.error(getLogger(), "onError: " + player + " - " + message);
boolean delegated = false;
try
{
if (isPreparing() && delegateOnError)
{
delegatePlayback();
delegated = true;
}
}
catch (Exception e)
{
L.error(getLogger(), "onError: error delegating playback -> " + player, e);
}
if (!delegated)
{
notifyError(new Exception(message));
}
return true;
}
});
...
这是崩溃......
java.lang.NullPointerException
at android.view.SurfaceView.updateWindow(SurfaceView.java:574)
at android.view.SurfaceView.access$000(SurfaceView.java:81)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:671)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1820)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)