MediaPlayer如何从视频的第五秒开始播放?

时间:2018-10-24 01:58:40

标签: android android-mediaplayer

我想跳过视频的标题播放,但是我不知道该怎么做。如果您知道,请告诉我,谢谢。

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

                        }
                    });

2 个答案:

答案 0 :(得分:1)

请使用mediyaPlayer.seekTo(milliseconds).

答案 1 :(得分:0)

使用MediaPlayer#seekTo(int msec)查找您想要设置的指定位置