代码之家  ›  专栏  ›  技术社区  ›  Twing90

视频播放器studio mp4[副本]

  •  0
  • Twing90  · 技术社区  · 7 年前

    我想在对话框窗口中播放视频,但它不起作用。视频不是“原始”目录。我不知道我哪里错了。你能帮我吗? 这是密码

    ImageButton video_player = (ImageButton) findViewById(R.id.img_btt_on_ear_watch);
            video_player.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    final Dialog dialog = new Dialog(context);
                    dialog.setContentView(R.layout.layout_video_player);
    
                    String filePlace = "android.resource://" + getPackageName() + "/" + R.raw.grado_video_cuffie_making;
                    VideoView videoV = (VideoView) findViewById(R.id.vv_video_player);
                    Uri videoURI = Uri.parse((String) filePlace);
                    videoV.setVideoURI(videoURI); //this is the 128 raw
                    videoV.setMediaController(new MediaController(context));
                    videoV.start();
    
                    ImageButton dialogButton = (ImageButton) dialog.findViewById(R.id.img_btt_vv_close);
                    // if button is clicked, close the custom dialog
                    dialogButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            dialog.dismiss();
                        }
                    });
    
                    dialog.show();
    
                }
            });
    

    这是Logcat

    11-15 10:40:50.666 3893-3893/com.huawei.headphones.huaweimusic E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                     Process: com.huawei.headphones.huaweimusic, PID: 3893
                                                                                     java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.VideoView.setVideoURI(android.net.Uri)' on a null object reference
                                                                                         at com.huawei.headphones.huaweimusic.Activity_Cuffia1$1.onClick(Activity_Cuffia1.java:128)
                                                                                         at android.view.View.performClick(View.java:5610)
                                                                                         at android.view.View$PerformClick.run(View.java:22265)
                                                                                         at android.os.Handler.handleCallback(Handler.java:751)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                         at android.os.Looper.loop(Looper.java:154)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Goku Farhana Naaz Ansari    7 年前

    使用此

     VideoView videoV = (VideoView) dialog.findViewById(R.id.vv_video_player);
    

    取而代之的是

    VideoView videoV = (VideoView) findViewById(R.id.vv_video_player);