简体   繁体   中英

Change MediaPlayer URI

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).

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();
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM