ksvc / KSYMediaPlayer_Android

金山云Android播放SDK(KSYUN Live Streaming player SDK),支持RTMP HTTP-FLV HLS 协议(supporting RTMP HTTP-FLV HLS protocol),直播延时2-3秒(Living delay 2 or 3 seconds),supporting jitter control,software&hardware decode
http://v.ksyun.com/
Apache License 2.0
854 stars 246 forks source link

seekTo issue #199

Open zaizaixinhtrai opened 6 years ago

zaizaixinhtrai commented 6 years ago

After calling mMediaPlayer.seekTo(pos) and continuing to play, MediaPlayer.getDuration() sometime return 0. The video already saved in mp4 file. I am using libksylive 2.4.3

FirmianaRain commented 6 years ago

MediaPlayer.getDuration() will not change until calling reset, release

zaizaixinhtrai commented 6 years ago

Syslog:

- 11-07 14:00:09.763 27610-27610: reload http://static-devclients.belive.sg/livestreamrecord/140f9046ffe44ad4b610d3d383c79841.mp4
- 11-07 14:00:09.816 27610-30475: [zzy]MediaCodec meet an error
- 11-07 14:00:09.966 27610-27610: updateRecordedBufferedMessageInList
- 11-07 14:00:10.245 27610-27610: time 0 - mFollowHostButtonAnimationDuration 0
- 11-07 14:00:10.254 27610-27610: updateRecordedBufferedMessageInList
- 11-07 14:00:10.393 27610-27610: mMediaPlayer.getDuration()=0

Seems to have made a mistake and MediaPlayer has reloaded. And I am unsing getDuration() in my code:

public void onProgressChanged(SeekBar bar, int progress, boolean fromuser) {
            if (mPlayer == null) {
                return;
            }

            if (!fromuser) {
                // We're not interested in programmatically generated changes to
                // the progress bar's position.
                return;
            }

            long duration = mPlayer.getDuration();
            long newposition = (duration * progress) / 1000L;
            mPlayer.seekTo((int) newposition);
            if (mCurrentTime != null)
                mCurrentTime.setText(stringForTime((int) newposition));
        }

public void seekTo(int pos) {
            if (mMediaPlayer != null) {
                Timber.e("mMediaPlayer.getDuration()=" + mMediaPlayer.getDuration());
                if (pos == mMediaPlayer.getDuration()) {
                   // finish open video
                } else {
                    mMediaPlayer.seekTo((long) pos);
                }
        }

When I seekTo sometime getDuration() return 0 therefore It finish finish open video.

FirmianaRain commented 6 years ago

These are what player will do after calling reload: Step 1: clean media info about previous video Step 2: open the new video

Between Step 1 and Step 2, player do not have media info about previous video, so getDuration() will return 0.

zaizaixinhtrai commented 6 years ago

In my code I only call MediaPlayer.seekTo(pos) not open the new video. But why player call reload ?

FirmianaRain commented 6 years ago

I'm sure that reload will never be called in Player's code.