如何在Android中播放来自画廊的视频?

时间:2015-05-18 11:29:18

标签: java android video android-studio gallery

我正在尝试从画廊播放视频,但我只能到达画廊。 我有一个按钮,当我按下它时,我被重定向到画廊。我可以看到有视频,但是当我按下视频时,应用程序崩溃了。

这是“活动结果”。

public void onActivityResult(int requestCode,int resultCode,Intent data){
    super.onActivityResult(requestCode,resultCode,data);

    if (requestCode == SELECT_PHOTO ) {
        Uri mVideoURI  = data.getData();
        video_player_view.setMediaController(media_Controller);

        video_player_view.setVideoURI(mVideoURI);

        video_player_view.requestFocus();
        video_player_view.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                video_player_view.start();
            }
        });

    }
}

这是“On Create”

   super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btn_camera = (Button)findViewById(R.id.btn_camera);
    Button btn_arhiva = (Button)findViewById(R.id.btn_arhiva);

    video_player_view = (VideoView)findViewById(R.id.video_player_view);
    media_Controller = new MediaController(this);
    media_Controller.setAnchorView(video_player_view);

    btn_camera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
            startActivityForResult(intent,CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);
        }
    });

    btn_arhiva.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*,video/*");
            startActivityForResult(photoPickerIntent, SELECT_PHOTO);
        }
    });

例外:

 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=199, result=-1, data=Intent { dat=content://media/external/video/media/39 }} to activity {licenta.licenta/licenta.licenta.MainActivity}:

 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.VideoView.setMediaController(android.widget.MediaController)' on a null object reference`

我在线搜索,并使用“Raw”目录中的视频制作教程。但我动态地想要它。如果我现在录制视频,我希望能够通过应用程序播放它。

谢谢!

0 个答案:

没有答案