视频播出后媒体播放器崩溃

时间:2011-10-12 07:07:38

标签: android video

我在这个问题上工作了一个星期,但没有发现任何问题。请帮我。任何人。一切都是受欢迎的。 应用程序运行,播放第一个视频,然后崩溃。它在模拟器(andoid 3.2),与Android 2.3的HTC手机上运行良好,但在Dreambook w7与android 2.2崩溃。

我建议这是因为Android 2.2及更高版本之间的VideoView类有些不同。可能有人知道我在哪里可以找到VideoView源代码?我将它包含在我的项目中。或者可能有一些开源视频播放器,不是基于VideoView?

这是我的代码:

@Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        requestWindowFeature(Window.FEATURE_NO_TITLE); 
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(R.layout.main);
        video=(VideoView)findViewById(R.id.video);

        /*some code for downloading playlist and missed videos here*/

        /*Then, launches some background theards for updating tham*/

        /*Then, downloading some picture from URL and setting it to image view*/

        /*Then, setting up another background theard for setting current time to text view*/

        //So, here is player: 
      File clip=new File(Environment.getExternalStorageDirectory(),
                playList[FLcurrentVideo].substring(2, playList[FLcurrentVideo].length()-1)+".mp4");     
                if (FLReady[FLcurrentVideo]==1) {

                    video.setVideoPath(clip.getAbsolutePath());
                    video.requestFocus();
                    video.start();
                    sendLog();     //send some info to web server
                }
                else {   //if video didn't exists
                    if (FLReady[FLcurrentVideo] == 0) {
                        new CheckOutVideos(false).execute(FLcurrentVideo);
                    }
                }


              /*Setting completion, for starting play next video after previous done...*/


              video.setOnCompletionListener(new OnCompletionListener(){
                @Override
                public void onCompletion(MediaPlayer mp) {
                    Log.d ("111", "on Completion"); //... but, this NEVER colled
                    int FL = 1;
                    while (FL == 1) {
                    if (FLcurrentVideo<count-1) FLcurrentVideo++;
                    else FLcurrentVideo = 0;
                    File clip=new File(Environment.getExternalStorageDirectory(),
                            playList[FLcurrentVideo].substring(2, playList[FLcurrentVideo].length()-1)+".mp4");

                            if (FLReady[FLcurrentVideo]==1) {

                                FL=0;
                                video=(VideoView)findViewById(R.id.video);
                                video.setVideoPath(clip.getAbsolutePath());
                                video.requestFocus();
                                video.start();

                            }
                            else {
                                FL = 1;
                                if (FLReady[FLcurrentVideo] == 0) {
                                new CheckOutVideos(false).execute(FLcurrentVideo);
                                }
                            }
                    }

                }
              });

    }

在核对OnCompletion后出现“空指针异常”:

09-22 11:50:54.553: ERROR/AndroidRuntime(4529): FATAL EXCEPTION: main
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): java.lang.NullPointerException
09-22 11:50:54.553: ERROR/AndroidRuntime(4529):     at android.widget.VideoView$3.onCompletion(VideoView.java:347)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529):     at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:1304)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529):     at android.os.Looper.loop(Looper.java:123)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529):     at java.lang.reflect.Method.invokeNative(Native Method)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529):     at java.lang.reflect.Method.invoke(Method.java:521)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

在OnComplition中,只需删除此行

即可
video=(VideoView)findViewById(R.id.video);

只需将绝对路径传递给您在onCreate()

上创建的旧videoView