Skip to content

Commit

Permalink
qml: fix autoplay load twice if play() after set source
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jun 30, 2015
1 parent 68e8e9b commit b3b1555
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions qml/QmlAV/QmlAVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ private Q_SLOTS:
bool mAutoLoad;
bool mHasAudio, mHasVideo;
bool m_fastSeek;
bool m_loading;
int mLoopCount;
qreal mPlaybackRate;
qreal mVolume;
Expand Down
10 changes: 9 additions & 1 deletion qml/QmlAVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ QmlAVPlayer::QmlAVPlayer(QObject *parent) :
, mHasAudio(false)
, mHasVideo(false)
, m_fastSeek(false)
, m_loading(false)
, mLoopCount(1)
, mPlaybackRate(1.0)
, mVolume(1.0)
Expand Down Expand Up @@ -515,6 +516,7 @@ void QmlAVPlayer::setPlaybackState(PlaybackState playbackState)
if (!vcopt.isEmpty())
mpPlayer->setOptionsForVideoCodec(vcopt);
}
m_loading = true;
mpPlayer->play();
}
break;
Expand All @@ -525,6 +527,7 @@ void QmlAVPlayer::setPlaybackState(PlaybackState playbackState)
case StoppedState:
mpPlayer->stop();
mpPlayer->unload();
m_loading = false;
mPlaybackState = StoppedState;
break;
default:
Expand Down Expand Up @@ -554,7 +557,7 @@ AVPlayer* QmlAVPlayer::player()

void QmlAVPlayer::play(const QUrl &url)
{
if (mSource == url && playbackState() != StoppedState)
if (mSource == url && (playbackState() != StoppedState || m_loading))
return;
setSource(url);
if (!autoPlay())
Expand All @@ -563,6 +566,8 @@ void QmlAVPlayer::play(const QUrl &url)

void QmlAVPlayer::play()
{
if (playbackState() != StoppedState || m_loading)
return;
setPlaybackState(PlayingState);
}

Expand Down Expand Up @@ -624,6 +629,8 @@ void QmlAVPlayer::_q_error(const AVError &e)
mError = AccessDenied;
//else
// err = ServiceMissing;
if (ec != AVError::NoError)
m_loading = false;
emit error(mError, mErrorString);
emit errorChanged();
}
Expand All @@ -647,6 +654,7 @@ void QmlAVPlayer::_q_paused(bool p)

void QmlAVPlayer::_q_started()
{
m_loading = false;
mPlaybackState = PlayingState;
applyChannelLayout();
// applyChannelLayout() first because it may reopen audio device
Expand Down

0 comments on commit b3b1555

Please sign in to comment.