Jellyfin Qt
QML Library for interacting with the Jellyfin multimedia server
Loading...
Searching...
No Matches
playbackmanager.h
Go to the documentation of this file.
1/*
2 * Sailfin: a Jellyfin client written using Qt
3 * Copyright (C) 2021-2022 Chris Josten and the Sailfin Contributors.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19#ifndef JELLYFIN_VIEWMODEL_PLAYBACKMANAGER_H
20#define JELLYFIN_VIEWMODEL_PLAYBACKMANAGER_H
21
22#include <QAbstractItemModel>
23#include <QFuture>
24#include <QJsonArray>
25#include <QJsonObject>
26#include <QLoggingCategory>
27#include <QObject>
28#include <QSharedPointer>
29#include <QtGlobal>
30#include <QUrlQuery>
31#include <QVariant>
32
33#include <QtMultimedia/QMediaPlayer>
34#include <QtMultimedia/QMediaPlaylist>
35
36#include <functional>
37
50#include "itemmodel.h"
51
52
53namespace Jellyfin {
54
55// Forward declaration of Jellyfin::ApiClient found in jellyfinapiclient.h
56class ApiClient;
57class ItemModel;
58
59namespace DTO {
61}
62
63namespace ViewModel {
65
67
76class PlaybackManager : public QObject, public QQmlParserStatus {
77 Q_OBJECT
78 Q_DECLARE_PRIVATE(PlaybackManager);
79 Q_INTERFACES(QQmlParserStatus)
80public:
81
82 explicit PlaybackManager(QObject *parent = nullptr);
83 virtual ~PlaybackManager();
84
85 Q_PROPERTY(ApiClient *apiClient READ apiClient WRITE setApiClient)
92
93 Q_PROPERTY(int audioIndex READ audioIndex WRITE setAudioIndex NOTIFY audioIndexChanged)
95 Q_PROPERTY(QString streamUrl READ streamUrl NOTIFY streamUrlChanged)
96 //Q_PROPERTY(bool autoOpen MEMBER m_autoOpen NOTIFY autoOpenChanged)
102
103 // Current Item and queue information
104 Q_PROPERTY(QObject *item READ item NOTIFY itemChanged)
105 Q_PROPERTY(int queueIndex READ queueIndex NOTIFY queueIndexChanged)
106 Q_PROPERTY(Jellyfin::ViewModel::Playlist *queue READ queue NOTIFY queueChanged)
107
108 // Current media player related property getters
109 Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
110 Q_PROPERTY(QMediaPlayer::Error error READ error NOTIFY errorChanged)
111 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
112 Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
113 Q_PROPERTY(bool seekable READ seekable NOTIFY seekableChanged)
114 Q_PROPERTY(QObject* mediaObject READ mediaObject NOTIFY mediaObjectChanged);
115 Q_PROPERTY(Jellyfin::Model::MediaStatusClass::Value mediaStatus READ mediaStatus NOTIFY mediaStatusChanged)
116 Q_PROPERTY(Jellyfin::Model::PlayerStateClass::Value playbackState READ playbackState NOTIFY playbackStateChanged)
117 Q_PROPERTY(qint64 position READ position NOTIFY positionChanged)
118 Q_PROPERTY(bool hasNext READ hasNext NOTIFY hasNextChanged)
119 Q_PROPERTY(bool hasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
122
123 // R/W props
124 ApiClient *apiClient() const;
126 bool resumePlayback() const;
127 void setResumePlayback(bool newResumePlayback);
128 int audioIndex() const;
129 void setAudioIndex(int newAudioIndex);
130 int subtitleIndex() const;
131 void setSubtitleIndex(int newAudioIndex);
132
133 ViewModel::Item *item() const;
134 QSharedPointer<Model::Item> dataItem() const;
135
136 QSharedPointer<Model::ControllableSession> controllingSession() const;
137 void setControllingSession(QSharedPointer<Model::ControllableSession> session);
138 QString controllingSessionId() const;
139 QString controllingSessionName() const;
140 bool controllingSessionLocal() const;
141 QString streamUrl() const;
142 PlayMethod playMethod() const;
143 qint64 position() const;
144 qint64 duration() const;
145 ViewModel::Playlist *queue() const;
146 int queueIndex() const;
147 bool hasNext() const;
148 bool hasPrevious() const;
149
150 // Current media player related property getters
151 QObject* mediaObject() const;
152 Model::PlayerState playbackState() const;
153 Model::MediaStatus mediaStatus() const;
154 bool hasVideo() const;
155 bool seekable() const;
156 QMediaPlayer::Error error () const;
157 QString errorString() const;
158
159 bool handlePlaystateCommands() const;
160 void setHandlePlaystateCommands(bool newHandlePlaystateCommands);
161signals:
167 void streamUrlChanged(const QString &newStreamUrl);
168 void autoOpenChanged(bool autoOpen);
171 void mediaPlayerChanged(QObject *newMediaPlayer);
172 void resumePlaybackChanged(bool newResumePlayback);
173 void playMethodChanged(PlayMethod newPlayMethod);
174
175 // Emitted when seek has been called.
176 void seeked(qint64 newPosition);
177
178 void hasNextChanged(bool newHasNext);
179 void hasPreviousChanged(bool newHasPrevious);
180
181 // Current media player related property signals
182 void mediaObjectChanged(QObject *newPlayer);
183 void positionChanged(qint64 newPosition);
184 void durationChanged(qint64 newDuration);
185 void queueChanged(QAbstractItemModel *newQueue);
186 void queueIndexChanged(int newIndex);
187 void playbackStateChanged(Jellyfin::Model::PlayerStateClass::Value newState);
188 void mediaStatusChanged(Jellyfin::Model::MediaStatusClass::Value newMediaStatus);
189 void hasVideoChanged(bool newHasVideo);
190 void seekableChanged(bool newSeekable);
191 void errorChanged(QMediaPlayer::Error newError);
192 void errorStringChanged(const QString &newErrorString);
193 void handlePlaystateCommandsChanged(bool newHandlePlaystateCommands);
194public slots:
202 void playItem(Item *item);
203
204 void playItem(QSharedPointer<Model::Item> item);
213 void playItemId(const QString &itemId);
214 void playItemInList(ItemModel *itemList, int index);
219 void skipToItemIndex(int index);
220 void play();
221 void pause();
222 void seek(qint64 pos);
223 void stop();
224
228 void previous();
229
233 void next();
234
235 void handlePlaystateRequest(const DTO::PlaystateRequest &request);
236
237private slots:
238 void mediaPlayerItemChanged();
239private:
241 const static int MS_TICK_FACTOR = 10000;
242
243
244
245 QMediaPlayer::Error m_error = QMediaPlayer::NoError;
246
247 // QQmlParserListener interface
248 void classBegin() override { m_qmlIsParsingComponent = true; }
249 void componentComplete() override;
250 bool m_qmlIsParsingComponent = false;
251
252 QScopedPointer<PlaybackManagerPrivate> d_ptr;
253};
254
255} // NS ViewModel
256} // NS Jellyfin
257
258#endif // JELLYFIN_VIEWMODEL_PLAYBACKMANAGER_H
An Api client for Jellyfin. Handles requests and authentication.
Definition apiclient.h:90
Definition playmethod.h:46
Value
Definition playmethod.h:49
Definition playstaterequest.h:49
Base class for each model that works with items.
Definition itemmodel.h:360
Definition item.h:104
Definition playbackmanager.cpp:46
The PlaybackManager class manages the playback of Jellyfin items.
Definition playbackmanager.h:76
void skipToItemIndex(int index)
skipToItemIndex Skips to an item in the current playlist
Definition playbackmanager.cpp:368
Jellyfin::Model::PlayerStateClass::Value playbackState
Definition playbackmanager.h:116
bool hasNext
Definition playbackmanager.h:118
QObject * mediaObject
Definition playbackmanager.h:114
void playItemId(const QString &itemId)
playItem Replaces the current queue and plays the item with the given id.
Definition playbackmanager.cpp:358
QString streamUrl
Definition playbackmanager.h:95
void playItemInList(ItemModel *itemList, int index)
Definition playbackmanager.cpp:363
void mediaPlayerChanged(QObject *newMediaPlayer)
void resumePlaybackChanged(bool newResumePlayback)
void seek(qint64 pos)
Definition playbackmanager.cpp:383
void mediaObjectChanged(QObject *newPlayer)
void seekableChanged(bool newSeekable)
void setControllingSession(QSharedPointer< Model::ControllableSession > session)
Definition playbackmanager.cpp:154
bool handlePlaystateCommands
Whether playstate commands received over the websocket should be handled.
Definition playbackmanager.h:121
int queueIndex
Definition playbackmanager.h:105
qint64 duration
Definition playbackmanager.h:109
bool controllingSessionLocal
Definition playbackmanager.h:91
void setApiClient(ApiClient *apiClient)
Definition playbackmanager.cpp:84
void positionChanged(qint64 newPosition)
void queueChanged(QAbstractItemModel *newQueue)
void stop()
Definition playbackmanager.cpp:389
QObject * item
Definition playbackmanager.h:104
void setHandlePlaystateCommands(bool newHandlePlaystateCommands)
Definition playbackmanager.cpp:327
bool seekable
Definition playbackmanager.h:113
bool resumePlayback
Definition playbackmanager.h:100
void durationChanged(qint64 newDuration)
void audioIndexChanged(int audioIndex)
void hasPreviousChanged(bool newHasPrevious)
PlaybackManager(QObject *parent=nullptr)
Definition playbackmanager.cpp:74
bool hasVideo
Definition playbackmanager.h:112
Jellyfin::DTO::PlayMethodClass::Value playMethod
Definition playbackmanager.h:101
virtual ~PlaybackManager()
Definition playbackmanager.cpp:80
void errorChanged(QMediaPlayer::Error newError)
void playItem(Item *item)
playItem Replaces the current queue and plays the given item.
Definition playbackmanager.cpp:348
qint64 position
Definition playbackmanager.h:117
void previous()
previous Play the previous track in the current playlist.
Definition playbackmanager.cpp:399
void play()
Definition playbackmanager.cpp:373
void playbackStateChanged(Jellyfin::Model::PlayerStateClass::Value newState)
QString controllingSessionId
Definition playbackmanager.h:86
void playMethodChanged(PlayMethod newPlayMethod)
QString controllingSessionName
Definition playbackmanager.h:87
void pause()
Definition playbackmanager.cpp:378
void hasVideoChanged(bool newHasVideo)
bool hasPrevious
Definition playbackmanager.h:119
void setResumePlayback(bool newResumePlayback)
Definition playbackmanager.cpp:110
ApiClient * apiClient
Definition playbackmanager.h:85
void setSubtitleIndex(int newAudioIndex)
Definition playbackmanager.cpp:130
void handlePlaystateCommandsChanged(bool newHandlePlaystateCommands)
QString errorString
Definition playbackmanager.h:111
Jellyfin::ViewModel::Playlist * queue
Definition playbackmanager.h:106
void setAudioIndex(int newAudioIndex)
Definition playbackmanager.cpp:120
void streamUrlChanged(const QString &newStreamUrl)
QSharedPointer< Model::Item > dataItem() const
Definition playbackmanager.cpp:139
void hasNextChanged(bool newHasNext)
int audioIndex
Definition playbackmanager.h:93
void errorStringChanged(const QString &newErrorString)
void handlePlaystateRequest(const DTO::PlaystateRequest &request)
Definition playbackmanager.cpp:404
Jellyfin::Model::MediaStatusClass::Value mediaStatus
Definition playbackmanager.h:115
void subtitleIndexChanged(int subtitleIndex)
void seeked(qint64 newPosition)
QSharedPointer< Model::ControllableSession > controllingSession() const
Definition playbackmanager.cpp:149
void mediaStatusChanged(Jellyfin::Model::MediaStatusClass::Value newMediaStatus)
void next()
next Play the next track in the current playlist.
Definition playbackmanager.cpp:394
int subtitleIndex
Definition playbackmanager.h:94
QMediaPlayer::Error error
Definition playbackmanager.h:110
Playlist/queue that can be exposed to QML.
Definition playlist.h:54
Jellyfin::DTO::PlaystateRequest PlaystateRequest
Definition playstaterequest.h:106
Q_DECLARE_LOGGING_CATEGORY(playbackManager)