检测视频视图何时停止播放

发布于 2024-12-18 03:23:02 字数 1910 浏览 0 评论 0原文

我有这段代码用于在 VideoView 上播放视频,

myVideoView = (VideoView) findViewById(R.id.VideoView);
myVideoView.setVideoURI(Uri.parse(path));
myVideoView.requestFocus();
myVideoView.start();

当视频播放完毕时,我收到消息:“抱歉,无法播放该视频”。我想缓存视频播放完毕的那一刻。我该怎么做?

这是我的代码:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.video);

        Bundle extras = getIntent().getExtras();
        path = extras.getString("path");
        idPlaylist = extras.getString("idPlaylist");
        timer = extras.getString("timer");

        myVideoView = (VideoView) findViewById(R.id.VideoView);
        myVideoView.setVideoURI(Uri.parse(path));
        myVideoView.requestFocus();
        myVideoView.start();

        myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                Intent i = new Intent(getBaseContext(),
                        com.PlayerOrange.ViewPlaylist.class);
                i.putExtra("id", idPlaylist);
                i.putExtra("timer", timer);
                startActivity(i);
                finish();           
                }
          });

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        System.out.println("Playing "+myVideoView.isPlaying());
        if ((keyCode == KeyEvent.KEYCODE_BACK) && (myVideoView.isPlaying()==true)) {
                //nothing happens
        } else {
            Intent i = new Intent(getBaseContext(),
                    com.PlayerOrange.ViewPlaylist.class);
            i.putExtra("id", idPlaylist);
            i.putExtra("timer", timer);
            startActivity(i);
            finish();
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

I have this code for playing a video on a VideoView

myVideoView = (VideoView) findViewById(R.id.VideoView);
myVideoView.setVideoURI(Uri.parse(path));
myVideoView.requestFocus();
myVideoView.start();

When video is finish playing I get message :" Sorry, this video can't be played". I want to cache the moment when video is finish playing. How can I do this?

Here is my code :

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.video);

        Bundle extras = getIntent().getExtras();
        path = extras.getString("path");
        idPlaylist = extras.getString("idPlaylist");
        timer = extras.getString("timer");

        myVideoView = (VideoView) findViewById(R.id.VideoView);
        myVideoView.setVideoURI(Uri.parse(path));
        myVideoView.requestFocus();
        myVideoView.start();

        myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                Intent i = new Intent(getBaseContext(),
                        com.PlayerOrange.ViewPlaylist.class);
                i.putExtra("id", idPlaylist);
                i.putExtra("timer", timer);
                startActivity(i);
                finish();           
                }
          });

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        System.out.println("Playing "+myVideoView.isPlaying());
        if ((keyCode == KeyEvent.KEYCODE_BACK) && (myVideoView.isPlaying()==true)) {
                //nothing happens
        } else {
            Intent i = new Intent(getBaseContext(),
                    com.PlayerOrange.ViewPlaylist.class);
            i.putExtra("id", idPlaylist);
            i.putExtra("timer", timer);
            startActivity(i);
            finish();
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯淡〆 2024-12-25 03:23:02

你尝试过吗?

myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

    @Override
    public void onCompletion(MediaPlayer vmp) {
        Intent i = new Intent(getBaseContext(),
                    com.PlayerOrange.ViewPlaylist.class);
            i.putExtra("id", idPlaylist);
            i.putExtra("timer", timer);
            startActivity(i);
            currentActivityName.finish();           
    }
});  

还要确保您的 myVideoView 不是静态的。如果是,则删除静态...

更多信息 这里

看看视频播放完毕后启动 Activity

Android – 视频/音乐播放器示例

播放视频

OnCompletion 视频通知MediaController 和 VideView 用法?

Android - 视频监听器(或处理程序)完成

Have you tried?

myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

    @Override
    public void onCompletion(MediaPlayer vmp) {
        Intent i = new Intent(getBaseContext(),
                    com.PlayerOrange.ViewPlaylist.class);
            i.putExtra("id", idPlaylist);
            i.putExtra("timer", timer);
            startActivity(i);
            currentActivityName.finish();           
    }
});  

Also make sure your myVideoView not to have as static. If yes, then remove static..

More info here

Look at Starting Activity when video is finished playing

Android – Video/Music player sample

Playing Video

OnCompletion video notification on MediaController and VideView usage?

Android - Listener (or handler) for video finish

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文