Skip to content

Commit

Permalink
qml: add MediaPlayer.startPosition/stopPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed May 29, 2016
1 parent 77833f4 commit 1b7167e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
18 changes: 17 additions & 1 deletion qml/QmlAV/QmlAVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class QmlAVPlayer : public QObject, public QQmlParserStatus
Q_ENUMS(Error)
Q_ENUMS(ChannelLayout)
// not supported by QtMultimedia
Q_ENUMS(PositionValue)
Q_PROPERTY(int startPosition READ startPosition WRITE setStartPosition NOTIFY startPositionChanged)
Q_PROPERTY(int stopPosition READ stopPosition WRITE setStopPosition NOTIFY stopPositionChanged)
Q_PROPERTY(bool fastSeek READ isFastSeek WRITE setFastSeek NOTIFY fastSeekChanged)
Q_PROPERTY(int timeout READ timeout WRITE setTimeout NOTIFY timeoutChanged)
Q_PROPERTY(bool abortOnTimeout READ abortOnTimeout WRITE setAbortOnTimeout NOTIFY abortOnTimeoutChanged)
Expand All @@ -88,6 +91,7 @@ class QmlAVPlayer : public QObject, public QQmlParserStatus
Q_PROPERTY(QStringList supportedAudioBackends READ supportedAudioBackends)
public:
enum Loop { Infinite = -1 };
enum PositionValue { PositionMax = (1<<31)-1};
enum PlaybackState {
StoppedState,
PlayingState,
Expand Down Expand Up @@ -133,7 +137,7 @@ class QmlAVPlayer : public QObject, public QQmlParserStatus
QUrl source() const;
void setSource(const QUrl& url);

// 0,1: play once. Loop.Infinite: forever.
// 0,1: play once. MediaPlayer.Infinite: forever.
// >1: play loopCount() - 1 times. different from Qt
int loopCount() const;
void setLoopCount(int c);
Expand All @@ -147,6 +151,15 @@ class QmlAVPlayer : public QObject, public QQmlParserStatus
int duration() const;
int position() const;
bool isSeekable() const;

int startPosition() const;
void setStartPosition(int value);
int stopPosition() const;
/*!
* \brief setStopPosition
* You can use MediaPlayer.PositionMax to play until the end of stream.
*/
void setStopPosition(int value);
bool isFastSeek() const;
void setFastSeek(bool value);

Expand Down Expand Up @@ -249,6 +262,8 @@ public Q_SLOTS:
void paused();
void stopped();
void playing();
void startPositionChanged();
void stopPositionChanged();
void seekableChanged();
void seekFinished(); //WARNING: position() now is not the seek finished video timestamp
void fastSeekChanged();
Expand Down Expand Up @@ -304,6 +319,7 @@ private Q_SLOTS:
bool m_fastSeek;
bool m_loading;
int mLoopCount;
int mStart, mStop;
qreal mPlaybackRate;
qreal mVolume;
PlaybackState mPlaybackState;
Expand Down
43 changes: 43 additions & 0 deletions qml/QmlAVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ QmlAVPlayer::QmlAVPlayer(QObject *parent) :
, m_fastSeek(false)
, m_loading(false)
, mLoopCount(1)
, mStart(0)
, mStop(PositionMax)
, mPlaybackRate(1.0)
, mVolume(1.0)
, mPlaybackState(StoppedState)
Expand Down Expand Up @@ -565,6 +567,41 @@ bool QmlAVPlayer::isSeekable() const
return mpPlayer && mpPlayer->isSeekable();
}

int QmlAVPlayer::startPosition() const
{
return mStart;
}

void QmlAVPlayer::setStartPosition(int value)
{
if (mStart == value)
return;
mStart = value;
Q_EMIT startPositionChanged();
if (mpPlayer) {
mpPlayer->setStartPosition(mStart);
}
}

int QmlAVPlayer::stopPosition() const
{
return mStop;
}

void QmlAVPlayer::setStopPosition(int value)
{
if (mStop == value)
return;
mStop = value;
Q_EMIT stopPositionChanged();
if (mpPlayer) {
if (value == PositionMax)
mpPlayer->setStopPosition();
else
mpPlayer->setStopPosition(value);
}
}

bool QmlAVPlayer::isFastSeek() const
{
return m_fastSeek;
Expand Down Expand Up @@ -632,6 +669,12 @@ void QmlAVPlayer::setPlaybackState(PlaybackState playbackState)
if (!vcopt.isEmpty())
mpPlayer->setOptionsForVideoCodec(vcopt);
}
mpPlayer->setStartPosition(startPosition());
if (stopPosition() == PositionMax)
mpPlayer->setStopPosition();
else
mpPlayer->setStopPosition(stopPosition());

m_loading = true;
mpPlayer->stop();
// change backends is not thread safe now, so change when stopped
Expand Down
4 changes: 3 additions & 1 deletion qml/Video.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import QtAV 1.7
\qml
import QtQuick 2.0
import QtAV 1.3
import QtAV 1.7
Video {
id: video
Expand Down Expand Up @@ -62,6 +62,8 @@ import QtAV 1.7
Item {
id: video

property alias startPosition: player.startPosition
property alias stopPosition: player.stopPosition
property alias videoFiltersGPU: videoOut.filters
property alias audioFilters: player.audioFilters
property alias videoFilters: player.videoFilters
Expand Down
8 changes: 8 additions & 0 deletions qml/plugins.qmltypes
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ Module {
"Infinite": -1
}
}
Enum {
name: "PositionValue"
values: {
"PositionMax": 2147483647
}
}
Enum {
name: "PlaybackState"
values: {
Expand Down Expand Up @@ -210,6 +216,8 @@ Module {
Property { name: "metaData"; type: "MediaMetaData"; isReadonly: true; isPointer: true }
Property { name: "mediaObject"; type: "QObject"; isReadonly: true; isPointer: true }
Property { name: "errorString"; type: "string"; isReadonly: true }
Property { name: "startPosition"; type: "int" }
Property { name: "stopPosition"; type: "int" }
Property { name: "fastSeek"; type: "bool" }
Property { name: "timeout"; type: "int" }
Property { name: "abortOnTimeout"; type: "bool" }
Expand Down

0 comments on commit 1b7167e

Please sign in to comment.