videoview完成后的android启动活动

时间:2015-12-15 11:04:06

标签: android android-activity android-mediaplayer android-videoview

我在我的原始文件夹中有videoview和mp4文件。我可以在videoview中成功播放我的视频。当视频完成后,我尝试开始第二个活动。我写了一些代码,但我有一个问题。我在视频结束后检查,在第二次活动开始之前,我有一两秒钟(第二次活动在一两秒后开始)

public  void getVideoFromHttp() {
    try {
        String uri = "android.resource://" + getPackageName() + "/" + FILE_NAME;
        MediaController mediacontroller = new MediaController(LauncherActivity.this);
        mediacontroller.setAnchorView(videoView);
        Uri mVideo = Uri.parse(uri);
        videoView.setMediaController(mediacontroller);
        videoView.setZOrderOnTop(true);
        videoView.setVideoURI(mVideo);
    } catch (Exception e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }
    videoView.requestFocus();
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        public void onPrepared(MediaPlayer mp) {
            videoView.start();

        }
    });

    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            Log.e("finished", "video finished");
            ClearStackAndStartActivity(CheckPinCodeActivity.class);
        }
    });

}


private  void ClearStackAndStartActivity(Class klass)
{
    Intent intent = new Intent(LauncherActivity.this, klass);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

}





final Runnable setImageRunnable = new Runnable() {
        public void run() {
          //start activity here
        }
    };
    TimerTask task = new TimerTask(){
        public void run() {
            runOnUiThread(setImageRunnable);
        }
    };

    Timer timer = new Timer();
    timer.schedule(task, 2000);

这是我的来源,我不知道我做错了什么。视频播放完毕后,是否可以开始第二项活动?谢谢大家。

0 个答案:

没有答案