完成后再次自动播放视频

时间:2014-12-16 08:06:40

标签: android android-videoview

我正在做Android应用程序相关的视频播放器。我播放视频但我想做视频完成时,它会自动恢复应用程序我该怎么办?我在我的应用程序中使用VideoView。

    // Displays a video file.
    VideoView mVideoView = (VideoView) findViewById(R.id.videoview);

    String uriPath = "android.resource://com.example.anket4dammy/"
            + R.raw.dunyagoz;
    Uri uri = Uri.parse(uriPath);
    mVideoView.setVideoURI(uri);
    mVideoView.requestFocus();

    mVideoView.start();

}

@Override
public boolean onTouchEvent(MotionEvent event) {
    int eventaction = event.getAction();

    switch (eventaction) {
    case MotionEvent.ACTION_DOWN:

        // timer.cancel();
        Intent intent = new Intent(getApplicationContext(),
                MainActivity.class);
        intent.putExtra("EXIT", false);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);

        break;


    }

    return true;
}


@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub

}

1 个答案:

答案 0 :(得分:1)

尝试以下代码

    // video finish listener
    mVideoView
            .setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

                @Override
                public void onCompletion(MediaPlayer mp) {
                    // not playVideo
                    // playVideo();

                    mp.start();
                }
            });