更改MediaPlayer URI

时间:2009-12-08 19:20:45

标签: android uri media-player

我有以下工作代码:

@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)。

1 个答案:

答案 0 :(得分:7)

我正在研究同样的问题。以下是我的想法:

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