视频不会参加第二项活动

时间:2017-08-31 17:02:50

标签: java android android-activity android-videoview

我有这个ImageButton播放链接到Main2Activity的视频。问题是当我点击ImageButton时,我录制的视频不会播放。一切都很顺利,直到我添加了第二个活动。我是Android开发的新手,还在学习,所以问题必须在于我如何连接这两项活动。

以下是我的代码:

MainActivity:



public class MainActivity extends AppCompatActivity {

    ImageButton imageButton;

    static final int REQUEST_VIDEO_CAPTURE = 1;
    VideoView resultvideo;
    MediaController mediacontroller;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        resultvideo = (VideoView)findViewById(R.id.videoView);
        mediacontroller = new MediaController(MainActivity.this);

        mediacontroller.setAnchorView(resultvideo);

        resultvideo.setMediaController(mediacontroller);

        Button click = (Button)findViewById(R.id.buttonRecord);
        resultvideo = (VideoView)findViewById(R.id.videoView);
    }

    public void dispatchTakeVideoIntent(View v) {
        Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        final Uri videoUri = data.getData();
        if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {

            resultvideo.setVideoURI(videoUri);

            resultvideo.pause();

        }
        imageButton = (ImageButton) findViewById(R.id.imageButton);
        {
            imageButton.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    Intent intent = new Intent(MainActivity.this, Main2Activity.class);
                    intent.putExtra("VIDEO_URI", videoUri.toString());
                    startActivity(intent);

                }
            });
        }
    }
}




Main2Activity:



public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        String uri = getIntent().getStringExtra("VIDEO_URI");
        Uri videoUri = Uri.parse(uri);

    }
}




0 个答案:

没有答案