MediaController.show()崩溃

时间:2011-11-09 13:16:21

标签: android tabs mediacontroller

我有一个mediacontroller的问题,这部分代码在不同的设备上完美地用作Acer Liquid(姜饼),Archos 43(froyo)和Archos 32(froyo)......

VideoView videoView = (VideoView) findViewById(R.id.videoView1);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView); 
File filevideo = new File(Environment.getExternalStorageDirectory() + "/edizionitsm/firenze/map_" + map_n + "/",filename + "_" + language + ".mp4");
Uri video = Uri.fromFile(filevideo);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();

...但是在Point of View Pro Tab2(姜饼)上它会在活动开始时崩溃。

11-09 14:12:59.640: E/AndroidRuntime(31433): FATAL EXCEPTION: main
11-09 14:12:59.640: E/AndroidRuntime(31433): java.lang.RuntimeException: Unable to start activity ComponentInfo{edizionitsm.archeoplayer/edizionitsm.archeoplayer.Player}: java.lang.NullPointerException
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.os.Looper.loop(Looper.java:123)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.app.ActivityThread.main(ActivityThread.java:3683)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at java.lang.reflect.Method.invokeNative(Native Method)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at java.lang.reflect.Method.invoke(Method.java:507)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at dalvik.system.NativeStart.main(Native Method)
11-09 14:12:59.640: E/AndroidRuntime(31433): Caused by: java.lang.NullPointerException
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.widget.MediaController.disableUnsupportedButtons(MediaController.java:640)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.widget.MediaController.show(MediaController.java:674)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.widget.MediaController.show(MediaController.java:631)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.widget.VideoView.start(VideoView.java:962)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at edizionitsm.archeoplayer.Player.onCreate(Player.java:48)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-09 14:12:59.640: E/AndroidRuntime(31433):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-09 14:12:59.640: E/AndroidRuntime(31433):    ... 11 more

问题出在mediacontroller类的函数show()中。我该如何解决? 谢谢。

1 个答案:

答案 0 :(得分:6)

我在3.1 Honeycomb上遇到了类似的问题,并使用setMediaPlayer来解决它。使用setMediaPlayer按此顺序尝试您的代码。

VideoView videoView = (VideoView) findViewById(R.id.videoView1);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);

mediaController.setMediaPlayer(videoView);

File filevideo = new File(Environment.getExternalStorageDirectory() + "/edizionitsm/firenze/map_" + map_n + "/",filename + "_" + language + ".mp4");
Uri video = Uri.fromFile(filevideo);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();