视频播放完毕后媒体播放器崩溃

发布于 2024-12-09 12:45:15 字数 4411 浏览 0 评论 0原文

我研究这个问题一周了,但没有找到任何问题。请帮我。任何人。一切都受到欢迎。 应用程序运行,播放第一个视频,然后崩溃。它在模拟器(andoid 3.2)、Android 2.3 的 HTC 手机上运行良好,但在 Android 2.2 的 Dreambook w7 上崩溃。

我认为这是因为 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);
                                }
                            }
                    }

                }
              });

    }

colling 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)

I worked on this problem for a week, but didn't find any. Please, help me. Anyone. Everything is welcome.
App runs, plays 1st video, then crashes. It works fine in the emulator (andoid 3.2), HTC phone with android 2.3, but crashes on Dreambook w7 with android 2.2.

I suggest this is becouse of some difference in VideoView class between android version 2.2 and later. May by someone knows where I can find VideoView source code? I'll include it into my project. Or may be there is some open source video players, based NOT on VideoView?

Here is my code:

@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);
                                }
                            }
                    }

                }
              });

    }

there is "null pointer exception" after colling 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尬尬 2024-12-16 12:45:15

在您的 OnComplition 中,只需删除此行,

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

只需将绝对路径传递到您在 onCreate() 创建的旧 videoView

In your OnComplition just remove this line

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

simply pass the absolute path to the old videoView which you have created onCreate()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文