Search code examples
androidandroid-mediaplayer

MediaPlayer How to start playing from the fifth second of the video?


I want to skip the video's title to play,But I don't know how to do it.If you know, please tell me, thank you.

MediaPlayer myMediaPlayer = new MediaPlayer();
                    myMediaPlayer.setDataSource(this, Uri.parse(uri));
                    holder = surfaceView.getHolder();
                    holder.addCallback(new MyCallBack());
                    myMediaPlayer.prepare();
                    mTimer = new Timer();
                     mTimerTask = new TimerTask() {
                        @Override
                        public void run() {
                            if (isChanging == true) {
                                return;
                            }
                            play_bar.setProgress(myMediaPlayer.getCurrentPosition());
                        }
                    };
                    mTimer.schedule(mTimerTask, 0, 100);
                    totale_time.setText(getTime(myMediaPlayer.getDuration() / 1000));
                    myMediaPlayer.start();
                    play_bar.setMax(myMediaPlayer.getDuration());
                    myMediaPlayer.setOnCompletionListener(new OnCompletionListener() {

                        @Override
                        public void onCompletion(MediaPlayer arg0) {
                            PlayVideoScreen.this.finish();

                        }
                    });

Solution

  • Please use mediyaPlayer.seekTo(milliseconds).