Skip to content

Commit

Permalink
qml: add some apis for player. speed, volume, duration, position
Browse files Browse the repository at this point in the history
TODO:
durationChanged and positionChanged not emit
  • Loading branch information
wang-bin committed Sep 4, 2013
1 parent 1be7ec0 commit 82c01bd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
14 changes: 14 additions & 0 deletions qml/QmlAV/QmlAVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ using namespace QtAV;
class QMLAV_EXPORT QmlAVPlayer : public QObject
{
Q_OBJECT
Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged)
Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
Q_PROPERTY(int position READ position NOTIFY positionChanged)
Q_PROPERTY(bool mute READ mute WRITE setMute NOTIFY muteChanged)
Q_PROPERTY(PlaybackState playbackState READ playbackState NOTIFY playbackStateChanged)
Q_PROPERTY(qreal speed READ speed WRITE setSpeed NOTIFY speedChanged)
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(QObject* videoOut READ videoOut WRITE setVideoOut NOTIFY videoOutChanged)
Q_ENUMS(PlaybackState)
Expand All @@ -50,10 +54,16 @@ class QMLAV_EXPORT QmlAVPlayer : public QObject
void setSource(const QUrl& url);
QObject* videoOut();
void setVideoOut(QObject* out);
qreal volume() const;
void setVolume(qreal volume);
bool mute() const;
void setMute(bool m);
int duration() const;
int position() const;
PlaybackState playbackState() const;
void setPlaybackState(PlaybackState playbackState);
qreal speed() const;
void setSpeed(qreal s);
Q_INVOKABLE void play(const QUrl& url);

public Q_SLOTS:
Expand All @@ -68,10 +78,14 @@ public Q_SLOTS:
void seekBackward();

Q_SIGNALS:
void volumeChanged();
void muteChanged();
void durationChanged();
void positionChanged();
void sourceChanged();
void videoOutChanged();
void playbackStateChanged();
void speedChanged();
void paused();
void stopped();
void playing();
Expand Down
42 changes: 42 additions & 0 deletions qml/QmlAVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "QmlAVPlayer.h"
#include <QtAV/AVPlayer.h>
#include <QtAV/AudioOutput.h>

QmlAVPlayer::QmlAVPlayer(QObject *parent) :
QObject(parent)
Expand Down Expand Up @@ -60,6 +61,24 @@ void QmlAVPlayer::setVideoOut(QObject *out)
mpVideoOut = static_cast<QQuickItemRenderer*>(out);
}

qreal QmlAVPlayer::volume() const
{
AudioOutput *ao = mpPlayer->audio();
if (ao && ao->isAvailable()) {
return ao->volume();
}
return 0;
}

void QmlAVPlayer::setVolume(qreal volume)
{
AudioOutput *ao = mpPlayer->audio();
if (ao && ao->isAvailable() && ao->volume() != volume) {
ao->setVolume(volume);
emit volumeChanged();
}
}

bool QmlAVPlayer::mute() const
{
return mpPlayer->isMute();
Expand All @@ -73,6 +92,16 @@ void QmlAVPlayer::setMute(bool m)
emit muteChanged();
}

int QmlAVPlayer::duration() const
{
return mpPlayer->duration();
}

int QmlAVPlayer::position() const
{
return mpPlayer->masterClock()->value();
}

QmlAVPlayer::PlaybackState QmlAVPlayer::playbackState() const
{
return mPlaybackState;
Expand Down Expand Up @@ -102,6 +131,19 @@ void QmlAVPlayer::setPlaybackState(PlaybackState playbackState)
}
}

qreal QmlAVPlayer::speed() const
{
return mpPlayer->speed();
}

void QmlAVPlayer::setSpeed(qreal s)
{
if (mpPlayer->speed() == s)
return;
mpPlayer->setSpeed(s);
emit speedChanged();
}

void QmlAVPlayer::play(const QUrl &url)
{
setSource(url);
Expand Down

0 comments on commit 82c01bd

Please sign in to comment.