playback/player: qt: add simple playlist support and wire buttons

This commit is contained in:
Alexandre Moreno 2015-11-01 16:30:43 +08:00 committed by Sebastian Dröge
parent 16a9b70155
commit 1cebdf926c
3 changed files with 90 additions and 4 deletions

View file

@ -43,6 +43,8 @@ ApplicationWindow {
objectName: "player"
volume: 0.5
positionUpdateInterval: 100
autoPlay: false
onStateChanged: {
if (state === Player.STOPPED) {
playbutton.state = "play"
@ -375,6 +377,11 @@ ApplicationWindow {
font.family: "FontAwesome"
text: FontAwesome.Icon.StepBackward
}
MouseArea {
anchors.fill: parent
onPressed: player.previous()
}
}
Item {
@ -432,6 +439,11 @@ ApplicationWindow {
font.family: "FontAwesome"
text: FontAwesome.Icon.StepForward
}
MouseArea {
anchors.fill: parent
onPressed: player.next()
}
}
Item {

View file

@ -354,7 +354,8 @@ Player::Player(QObject *parent, VideoRenderer *renderer)
"swapped-signal::video-dimensions-changed", G_CALLBACK (Player::onVideoDimensionsChanged), this,
"swapped-signal::volume-changed", G_CALLBACK (Player::onVolumeChanged), this,
"swapped-signal::mute-changed", G_CALLBACK (Player::onMuteChanged), this,
"swapped-signal::media-info-updated", G_CALLBACK (Player::onMediaInfoUpdated), this, NULL);
"swapped-signal::media-info-updated", G_CALLBACK (Player::onMediaInfoUpdated), this,
"swapped-signal::end-of-stream", G_CALLBACK (Player::onEndOfStreamReached), this, NULL);
mediaInfo_ = new MediaInfo(this);
gst_player_set_subtitle_track_enabled(player_, false);
@ -444,6 +445,63 @@ Player::onMediaInfoUpdated(Player *player, GstPlayerMediaInfo *media_info)
emit player->mediaInfoChanged();
}
void Player::onEndOfStreamReached(Player *player)
{
Q_ASSERT(player != 0);
emit player->endOfStream();
}
void Player::setUri(QUrl url)
{
Q_ASSERT(player_ != 0);
QByteArray uri = url.toString().toLocal8Bit();
gst_player_set_uri(player_, uri.data());
autoPlay_ ? play() : pause();
emit sourceChanged(url);
}
QList<QUrl> Player::playlist() const
{
return playlist_;
}
void Player::setPlaylist(const QList<QUrl> &playlist)
{
if (!playlist_.isEmpty()) {
playlist_.erase(playlist_.begin(), playlist_.end());
}
playlist_ = playlist;
iter_ = playlist_.begin();
setUri(*iter_);
}
void Player::next()
{
if (playlist_.isEmpty())
return;
if (iter_ == playlist_.end())
return;
setUri(*++iter_);
}
void Player::previous()
{
if (playlist_.isEmpty())
return;
if (iter_ == playlist_.begin())
return;
setUri(*--iter_);
}
bool Player::autoPlay() const
{
@ -554,9 +612,13 @@ void Player::seek(qint64 position)
void Player::setSource(QUrl const& url)
{
Q_ASSERT(player_ != 0);
QByteArray uri = url.toString().toLocal8Bit();
gst_player_set_uri(player_, uri.data());
// discard playlist
if (!playlist_.isEmpty()) {
playlist_.erase(playlist_.begin(), playlist_.end());
}
setUri(url);
emit sourceChanged(url);
}

View file

@ -25,7 +25,8 @@
#include <QUrl>
#include <QSize>
//#include <QtGui/qwindowdefs.h>
#include <QtQml/QQmlPropertyMap>
#include <QVariant>
#include <QList>
#include <gst/player/player.h>
namespace QGstPlayer {
@ -58,6 +59,7 @@ class Player : public QObject
Q_PROPERTY(bool subtitleEnabled READ isSubtitleEnabled WRITE setSubtitleEnabled
NOTIFY subtitleEnabledChanged)
Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay)
Q_PROPERTY(QList<QUrl> playlist READ playlist WRITE setPlaylist)
Q_ENUMS(State)
@ -91,10 +93,12 @@ public:
bool isSubtitleEnabled() const;
quint32 positionUpdateInterval() const;
bool autoPlay() const;
QList<QUrl> playlist() const;
signals:
void stateChanged(State new_state);
void bufferingChanged(int percent);
void endOfStream();
void positionUpdated(qint64 new_position);
void durationChanged(qint64 duration);
void resolutionChanged(QSize resolution);
@ -119,6 +123,9 @@ public slots:
void setCurrentSubtitle(QVariant track);
void setSubtitleEnabled(bool enabled);
void setPositionUpdateInterval(quint32 interval);
void setPlaylist(const QList<QUrl> &playlist);
void next();
void previous();
void setAutoPlay(bool auto_play);
private:
@ -131,6 +138,9 @@ private:
static void onVolumeChanged(Player *);
static void onMuteChanged(Player *);
static void onMediaInfoUpdated(Player *, GstPlayerMediaInfo *media_info);
static void onEndOfStreamReached(Player *);
void setUri(QUrl url);
GstPlayer *player_;
State state_;
@ -139,6 +149,8 @@ private:
bool videoAvailable_;
bool subtitleEnabled_;
bool autoPlay_;
QList<QUrl> playlist_;
QList<QUrl>::iterator iter_;
};
class VideoRenderer