return str+secs;
}
+
+ onDownChanged:
+ {
+ if(!down)
+ streamControl.position = value;
+ }
+ }
+
+ IconButton
+ {
+ id: playPauseButton
+ anchors.horizontalCenter: parent.horizontalCenter
+ property string action: (streamControl.playbackState==StreamControl.Playing ? "pause" : "play")
+ icon.source: "image://theme/icon-l-"+action
+ onPressed:
+ {
+ if(action=="play")
+ streamControl.playbackState = StreamControl.Playing;
+ else if(action=="pause")
+ streamControl.playbackState = StreamControl.Paused;
+ }
}
}
onPositionChanged:
{
if(!slider.down)
- slider.value = streamControl.position
+ slider.value = position;
}
}
}
if(control)
{
XinemaControl &xc = control->get_control();
+ connect(&xc, &XinemaControl::playback_state_changed, this, &StreamControlItem::playback_state_changed);
connect(&xc, &XinemaControl::title_changed, this, &StreamControlItem::title_changed);
connect(&xc, &XinemaControl::duration_changed, this, &StreamControlItem::duration_changed);
connect(&xc, &XinemaControl::position_changed, this, &StreamControlItem::position_changed);
if(control)
{
+ emit playback_state_changed();
emit title_changed();
emit duration_changed();
emit position_changed();
}
}
+StreamControlItem::PlaybackState StreamControlItem::get_playback_state() const
+{
+ if(!control)
+ return Stopped;
+
+ return static_cast<PlaybackState>(control->get_control().get_playback_state());
+}
+
+void StreamControlItem::set_playback_state(PlaybackState state)
+{
+ if(!control)
+ return;
+
+ XinemaControl &xc = control->get_control();
+ if(state==Stopped)
+ xc.stop();
+ else if(state==Paused)
+ xc.pause();
+ else if(state==Playing)
+ xc.play();
+}
+
QString StreamControlItem::get_title() const
{
if(!control)
return control->get_control().get_duration();
}
+void StreamControlItem::set_position(float pos)
+{
+ if(control)
+ control->get_control().seek(pos);
+}
+
float StreamControlItem::get_position() const
{
if(!control)
#define STREAMCONTROLITEM_H_
#include <QQuickItem>
+#include "xinemacontrol.h"
class XinemaControlItem;
Q_OBJECT
Q_PROPERTY(XinemaControlItem *control READ get_control WRITE set_control NOTIFY control_changed)
+ Q_PROPERTY(PlaybackState playbackState READ get_playback_state WRITE set_playback_state NOTIFY playback_state_changed)
Q_PROPERTY(QString title READ get_title NOTIFY title_changed)
Q_PROPERTY(float duration READ get_duration NOTIFY duration_changed)
- Q_PROPERTY(float position READ get_position NOTIFY position_changed)
+ Q_PROPERTY(float position READ get_position WRITE set_position NOTIFY position_changed)
+
+ Q_ENUMS(PlaybackState)
+
+public:
+ enum PlaybackState
+ {
+ Stopped = XinemaControl::STOPPED,
+ Paused = XinemaControl::PAUSED,
+ Playing = XinemaControl::PLAYING
+ };
private:
XinemaControlItem *control;
void set_control(XinemaControlItem *);
XinemaControlItem *get_control() const { return control; }
+ PlaybackState get_playback_state() const;
+ void set_playback_state(PlaybackState);
QString get_title() const;
float get_duration() const;
+ void set_position(float);
float get_position() const;
signals:
void control_changed();
+ void playback_state_changed();
void title_changed();
void duration_changed();
void position_changed();
#include "xinemacontrol.h"
-XinemaControl::XinemaControl()
+XinemaControl::XinemaControl():
+ playback_state(STOPPED),
+ duration(0.0f),
+ position(0.0f)
{
QObject::connect(&socket, &QAbstractSocket::connected, this, &XinemaControl::connected);
QObject::connect(&socket, &QAbstractSocket::disconnected, this, &XinemaControl::disconnected);
send_request("play_file "+fn);
}
+void XinemaControl::play()
+{
+ send_request("play");
+}
+
+void XinemaControl::seek(float time)
+{
+ send_request(QString("seek %1").arg(time));
+}
+
+void XinemaControl::pause()
+{
+ send_request("pause");
+}
+
+void XinemaControl::stop()
+{
+ send_request("stop");
+}
+
void XinemaControl::send_request(const QString &req)
{
socket.write(req.toUtf8());
emit subdirectory_added(args);
else if(keyword=="file")
emit file_added(args);
+ else if(keyword=="state")
+ {
+ if(args=="STOPPED")
+ playback_state = STOPPED;
+ else if(args=="PAUSED")
+ playback_state = PAUSED;
+ else if(args=="PLAYING")
+ playback_state = PLAYING;
+ emit playback_state_changed(playback_state);
+ }
else if(keyword=="title")
{
title = args;
{
Q_OBJECT
+public:
+ enum PlaybackState
+ {
+ STOPPED,
+ PAUSED,
+ PLAYING
+ };
+
private:
QTcpSocket socket;
QByteArray buffer;
+ PlaybackState playback_state;
QString title;
float duration;
float position;
void list_directory(const QString &);
void play_file(const QString &);
+ PlaybackState get_playback_state() const { return playback_state; }
const QString &get_title() const { return title; }
float get_duration() const { return duration; }
float get_position() const { return position; }
+ void play();
+ void seek(float);
+ void pause();
+ void stop();
+
signals:
void connected();
void disconnected();
void directory_started(const QString &);
void file_added(const QString &);
void subdirectory_added(const QString &);
+ void playback_state_changed(PlaybackState);
void title_changed(const QString &);
void duration_changed(float);
void position_changed(float);