Skip to content

Commit

Permalink
qml: autoLoad support
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jun 7, 2016
1 parent ba6dfab commit 4f2d676
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 4 additions & 0 deletions qml/QmlAV/QmlAVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 136,10 @@ class QmlAVPlayer : public QObject, public QQmlParserStatus
bool hasVideo() const;

QUrl source() const;
/*!
* \brief setSource
* If url is changed and auto load is true, current playback will stop.
*/
void setSource(const QUrl& url);

// 0,1: play once. MediaPlayer.Infinite: forever.
Expand Down
20 changes: 8 additions & 12 deletions qml/QmlAVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 104,13 @@ void QmlAVPlayer::componentComplete()
// TODO: set player parameters
if (mSource.isValid() && (mAutoLoad || mAutoPlay)) {
mpPlayer->setFile(QUrl::fromPercentEncoding(mSource.toEncoded()));
if (mAutoLoad)
mpPlayer->load();
if (mAutoPlay)
mpPlayer->play();
}

m_complete = true;

if (mAutoPlay) {
if (!mSource.isValid()) {
stop();
} else {
play();
}
}
}

bool QmlAVPlayer::hasAudio() const
Expand Down Expand Up @@ -159,8 155,9 @@ void QmlAVPlayer::setSource(const QUrl &url)
mErrorString = tr("No error");
Q_EMIT error(mError, mErrorString);
Q_EMIT errorChanged();
stop();
//mpPlayer->load(); //QtAV internal bug: load() or play() results in reload
stop(); // TODO: no stop for autoLoad?
if (mAutoLoad)
mpPlayer->load();
if (mAutoPlay) {
//mPlaybackState is actually changed in slots. But if set to a new source the state may not change before call play()
mPlaybackState = StoppedState;
Expand Down Expand Up @@ -676,8 673,7 @@ void QmlAVPlayer::setPlaybackState(PlaybackState playbackState)
mpPlayer->setStopPosition(stopPosition());

m_loading = true;
mpPlayer->stop();
// change backends is not thread safe now, so change when stopped
// TODO: change backends is not thread safe now, so change when stopped
mpPlayer->audio()->setBackends(m_ao);
mpPlayer->play();
}
Expand Down

0 comments on commit 4f2d676

Please sign in to comment.