更改媒体播放器 URI

发布于 2024-08-13 10:22:01 字数 932 浏览 1 评论 0原文

我有以下工作代码:

@Override
        protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.player);

        videoView = (VideoView)this.findViewById(R.id.videoView);
        playVideo();

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

                @Override
                public void onCompletion(MediaPlayer mp) {
                        mp.start();
                }
        });
    }

    public void playVideo() {
                MediaController mc = new MediaController(this);
                videoView.setMediaController(mc);
                videoView.setVideoURI(Uri.parse("http://sayedhashimi.com/downloads/android/movie.mp4"));
                videoView.requestFocus(); 
        }

我只想在视频结束时更改 MediaPlayer 数据源(setOnCompletionListener)。

I have the following working code:

@Override
        protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.player);

        videoView = (VideoView)this.findViewById(R.id.videoView);
        playVideo();

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

                @Override
                public void onCompletion(MediaPlayer mp) {
                        mp.start();
                }
        });
    }

    public void playVideo() {
                MediaController mc = new MediaController(this);
                videoView.setMediaController(mc);
                videoView.setVideoURI(Uri.parse("http://sayedhashimi.com/downloads/android/movie.mp4"));
                videoView.requestFocus(); 
        }

I just want to change the MediaPlayer data source when the video finishes (setOnCompletionListener).

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

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

发布评论

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

评论(2

也只是曾经 2024-08-20 10:22:01

我正在研究同样的问题。这是我想出的:

   public void onCompletion(MediaPlayer mp) {
       mp.reset();
       mp.setDataSource(this, newUri);
       mp.start();
   }

I'm working on this same issue. Here is what I've come up with:

   public void onCompletion(MediaPlayer mp) {
       mp.reset();
       mp.setDataSource(this, newUri);
       mp.start();
   }
轮廓§ 2024-08-20 10:22:01

这是我的解决方案:

mp.release()
mp = createNew(context,newUri)
mp.start()

我尝试的任何其他方法都给我带来了错误,如上所述这里
每次创建新的媒体播放器不会对性能造成太大损害,因为无论如何您很可能一次只有一个。

希望有帮助; )

Here is my solution:

mp.release()
mp = createNew(context,newUri)
mp.start()

Anything else I tried gave me errors as mentioned here.
Creating new media player every time won't be that harmful for performance as you will most likely have only one at a time anyway.

hope it helps ; )

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