From 4a72906531e01792e427ecd904ef2d2aaf39d653 Mon Sep 17 00:00:00 2001 From: pingkai Date: Mon, 14 Sep 2020 14:46:07 +0800 Subject: [PATCH] fix(supermediaplayer): update position when seek end Signed-off-by: pingkai --- mediaPlayer/SuperMediaPlayer.cpp | 33 +++++++------------------------- mediaPlayer/SuperMediaPlayer.h | 9 ++++----- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/mediaPlayer/SuperMediaPlayer.cpp b/mediaPlayer/SuperMediaPlayer.cpp index 165de1417..78c816a70 100644 --- a/mediaPlayer/SuperMediaPlayer.cpp +++ b/mediaPlayer/SuperMediaPlayer.cpp @@ -638,24 +638,9 @@ void SuperMediaPlayer::GetOption(const char *key, char *value) return; } -int64_t SuperMediaPlayer::GetCurrentPosition() -{ - return getCurrentPosition() / 1000; -} - void SuperMediaPlayer::NotifyPosition(int64_t position) { - mPlayingPosition = position; - mPNotifier->NotifyPosition(position); -} - -int64_t SuperMediaPlayer::GetPlayingPosition() -{ - if (isSeeking()) { - return mSeekPos / 1000; - } - - return mPlayingPosition; + mPNotifier->NotifyPosition(position / 1000); } int64_t SuperMediaPlayer::getCurrentPosition() @@ -1563,7 +1548,7 @@ void SuperMediaPlayer::doRender() } else { mCurrentPos = mPlayedVideoPts; } - NotifyPosition(getCurrentPosition() / 1000); + NotifyPosition(getCurrentPosition()); // seek preview can't render audio,but set the audio clock to here pts if (HAVE_AUDIO && (mAudioTime.startTime <= 0)) { @@ -1577,7 +1562,7 @@ void SuperMediaPlayer::doRender() } else {// audio only if (!mAudioFrameQue.empty()) { int64_t audioPTS = mAudioFrameQue.front()->getInfo().pts; - NotifyPosition(audioPTS / 1000); + NotifyPosition(audioPTS); rendered = true; mAudioTime.startTime = audioPTS; } @@ -1605,9 +1590,7 @@ void SuperMediaPlayer::doRender() // update position when seek end. in case of when paused. // update position before reset seek status, so getCurrentPosition return mSeekPos instead of mCurrentPos // fix bug the mCurrentPos not accuracy - if (mPlayStatus == PLAYER_PAUSED) { - NotifyPosition(getCurrentPosition() / 1000); - } + NotifyPosition(getCurrentPosition()); ResetSeekStatus(); mPNotifier->NotifySeekEnd(mSeekInCache); mSeekInCache = false; @@ -1750,7 +1733,7 @@ void SuperMediaPlayer::checkEOS() } } - NotifyPosition(mDuration / 1000); + NotifyPosition(mDuration); if (mSet->bLooping && mDuration > 0) { mSeekPos = 0;//19644161: need reset seek position @@ -2234,9 +2217,8 @@ void SuperMediaPlayer::OnTimer(int64_t curTime) * jumping */ if ((mPlayStatus == PLAYER_PLAYING) && !isSeeking()) { - int64_t pos = getCurrentPosition() / 1000; - //AF_LOGD("TIMEPOS OnTimer :%lld", pos); - NotifyPosition(pos); + //AF_LOGD("TIMEPOS OnTimer :%lld", getCurrentPosition()); + NotifyPosition(getCurrentPosition()); } PostBufferPositionMsg(); @@ -3318,7 +3300,6 @@ void SuperMediaPlayer::Reset() mVideoChangedFirstPts = INT64_MIN; mSubtitleChangedFirstPts = INT64_MIN; mSoughtVideoPos = INT64_MIN; - mPlayingPosition = 0; mFirstReadPacketSucMS = 0; mCanceled = false; mPNotifier->Enable(true); diff --git a/mediaPlayer/SuperMediaPlayer.h b/mediaPlayer/SuperMediaPlayer.h index 32d0e12ed..8ebead6a9 100644 --- a/mediaPlayer/SuperMediaPlayer.h +++ b/mediaPlayer/SuperMediaPlayer.h @@ -104,7 +104,10 @@ namespace Cicada { void GetOption(const char *key, char *value) override; - int64_t GetPlayingPosition() override; + int64_t GetPlayingPosition() override + { + return getCurrentPosition(); + }; int64_t GetBufferPosition() override; @@ -203,8 +206,6 @@ namespace Cicada { private: void NotifyPosition(int64_t position); - int64_t GetCurrentPosition(); - void OnTimer(int64_t curTime); void updateLoopGap(); @@ -487,8 +488,6 @@ namespace Cicada { bool mWillSwitchVideo{false}; std::unique_ptr mSet{}; int64_t mSoughtVideoPos{INT64_MIN}; - std::atomic mPlayingPosition{0}; - int mMaxRunningLoopGap = 10; int mTimerInterval = 0; int64_t mTimerLatestTime = 0;