怎么回去玩视频后 [英] How to go back after playing video

查看:111
本文介绍了怎么回去玩视频后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,使得与播放按钮的视频列表。当我点击播放按钮,一个独立的活动正在使用的意图开始。我只是想,当视频播放完毕后,活动应该自动完成自身并返回到主活动。这里是我的code创建videoview。

I have an application that makes a list of videos with play button. When I click on the play button, a separate activity is started using intent. I just want that when the video playback is finished, the activity should automatically finish itself and go back to the main Activity. Here is my code for creating videoview.

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.videoview);
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    filename = extras.getString("videofilename");
    mVideoView = (VideoView)findViewById(R.id.videoview);
    path=filename;
    if (path == "") {

        Toast.makeText(
                ViewVideo.this,
                "no video selected,
                Toast.LENGTH_LONG).show();

    } else {

          mVideoView.setVideoPath(path);
          mc = new MediaController(this);
          mVideoView.setMediaController(mc);
          mVideoView.requestFocus();
              mVideoView.start();

    }
}

任何建议???

any suggestions???

推荐答案

注册的<一个href=\"http://developer.android.com/reference/android/widget/VideoView.html#setOnCompletionListener%28android.media.MediaPlayer.OnCompletionListener%29\"相对=nofollow> OnCompletionListener 到videoView,在听者落实调用完成()

Register an OnCompletionListener to the videoView, in the listener implement the call to finish().

编辑(回答评论)

使用方法<一个href=\"http://developer.android.com/reference/android/widget/VideoView.html#setOnCompletionListener%28android.media.MediaPlayer.OnCompletionListener%29\"相对=nofollow> setOnCompletionListener :

mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    @Override
    public void onCompletion (MediaPlayer mp) {
        // your code to clean up and finish the activity...
    }
});

这篇关于怎么回去玩视频后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆