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_MODEL_PLAYBACKMANAGER_H
20#define JELLYFIN_MODEL_PLAYBACKMANAGER_H
21
22#include <QLoggingCategory>
23#include <QObject>
24#include <QSharedPointer>
25
28
29namespace Jellyfin {
30namespace Model {
31
32class Item;
33class Playlist;
34
36
48
50
59class PlaybackManager : public QObject {
60 Q_OBJECT
61 Q_DECLARE_PRIVATE(PlaybackManager);
63 Q_PROPERTY(int audioIndex READ audioIndex WRITE setAudioIndex NOTIFY audioIndexChanged)
68 Q_PROPERTY(qint64 position READ position NOTIFY positionChanged)
72 Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
76 Q_PROPERTY(bool seekable READ seekable NOTIFY seekableChanged)
80 Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged)
84 Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
87 Q_PROPERTY(int queueIndex READ queueIndex NOTIFY queueIndexChanged)
88public:
89 explicit PlaybackManager(QObject *parent = nullptr);
90 virtual ~PlaybackManager();
91 void swap(PlaybackManager& other);
92
93 ApiClient * apiClient() const;
95
96 // Getters
97 QSharedPointer<Item> currentItem() const;
98 Playlist *queue() const;
99 int queueIndex() const;
100
101 bool resumePlayback() const;
102 void setResumePlayback(bool newResumePlayback);
103 int audioIndex() const;
104 void setAudioIndex(int newAudioIndex);
105 int subtitleIndex() const;
106 void setSubtitleIndex(int newSubtitleIndex);
107
108 virtual PlayerState playbackState() const = 0;
109 virtual MediaStatus mediaStatus() const = 0;
110 virtual bool hasNext() const = 0;
111 virtual bool hasPrevious() const = 0;
112 virtual PlaybackManagerError error() const = 0;
113
114 virtual const QString &errorString() const = 0;
115 virtual qint64 position() const = 0;
116 virtual qint64 duration() const = 0;
117 virtual bool seekable() const = 0;
118 virtual bool hasAudio() const = 0;
119 virtual bool hasVideo() const = 0;
120
124 virtual void playItem(QSharedPointer<Model::Item> item) = 0;
130 virtual void playItemInList(const QList<QSharedPointer<Model::Item>> &items, int index) = 0;
131 static const qint64 MS_TICK_FACTOR = 10000;
132protected:
133 void setItem(QSharedPointer<Item> item);
134 void setQueueIndex(int index);
135
136signals:
137 void playbackStateChanged(Jellyfin::Model::PlayerStateClass::Value newPlaybackState);
138 void mediaStatusChanged(Jellyfin::Model::MediaStatusClass::Value newMediaStatus);
139 void queueChanged(Jellyfin::Model::Playlist *newPlaylist);
140 void hasNextChanged(bool newHasNext);
141 void hasPreviousChanged(bool newHasPrevious);
143 void queueIndexChanged(int index);
144 void errorChanged(Jellyfin::Model::PlaybackManagerErrorClass::Value newError);
145 void errorStringChanged(const QString &newErrorString);
146 void positionChanged(qint64 newPosition);
147 void durationChanged(qint64 newDuration);
148 void seekableChanged(bool newSeekable);
151 void resumePlaybackChanged(bool newPlaybackChanged);
152 void audioIndexChanged(int newAudioIndex);
153 void subtitleIndexChanged(int newSubtitleIndex);
154
155public slots:
156 virtual void pause() = 0;
157 virtual void play() = 0;
158 virtual void playItemId(const QString &id) = 0;
159 virtual void previous() = 0;
160 virtual void next() = 0;
165 virtual void goTo(int index) = 0;
166 virtual void stop() = 0;
167 virtual void seek(qint64 pos) = 0;
168protected:
169 explicit PlaybackManager(PlaybackManagerPrivate *d, QObject *parent = nullptr);
171};
172
188 Q_DECLARE_PRIVATE(LocalPlaybackManager);
189 Q_OBJECT
190 Q_PROPERTY(Jellyfin::Model::Player *player READ player NOTIFY playerChanged)
191 Q_PROPERTY(Jellyfin::DTO::PlayMethodClass::Value playMethod READ playMethod NOTIFY playMethodChanged)
192 Q_PROPERTY(QUrl streamUrl READ streamUrl NOTIFY streamUrlChanged)
193public:
194 explicit LocalPlaybackManager(QObject *parent = nullptr);
195
196 Player *player() const;
197 QString sessionId() const;
198 DTO::PlayMethod playMethod() const;
199 const QUrl &streamUrl() const;
200
201 PlayerState playbackState() const override;
202 MediaStatus mediaStatus() const override;
203 PlaybackManagerError error() const override;
204 const QString& errorString() const override;
205 qint64 position() const override;
206 qint64 duration() const override;
207 bool seekable() const override;
208 bool hasAudio() const override;
209 bool hasVideo() const override;
210
211 bool hasNext() const override;
212 bool hasPrevious() const override;
213
214 void playItemInList(const QList<QSharedPointer<Model::Item>> &items, int index) override;
215
216public slots:
217 void pause() override;
218 void play() override;
219 void playItem(QSharedPointer<Model::Item> item) override;
220 void playItemId(const QString &itemId) override;
221 void next() override;
222 void previous() override;
223 void stop() override;
224 void seek(qint64 pos) override;
225 void goTo(int index) override;
226signals:
227 void playerChanged(Jellyfin::Model::Player *newPlayer);
228 void playMethodChanged(Jellyfin::DTO::PlayMethodClass::Value newPlayMethod);
229 void streamUrlChanged(const QUrl &newStreamUrl);
230};
231
238
239} // NS Model
240} // NS Jellyfin
241
242#endif // JELLYFIN_MODEL_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 item.h:36
Definition playbackmanager.cpp:219
Controls playback whithin this app.
Definition playbackmanager.h:187
Definition player.h:45
Value
Definition player.h:48
Definition playbackmanager.h:37
Value
Definition playbackmanager.h:40
@ RemoteClientNotReachable
Definition playbackmanager.h:43
@ PlayerGeneralError
Definition playbackmanager.h:44
@ NoError
Definition playbackmanager.h:41
@ PlaybackInfoError
Definition playbackmanager.h:42
Definition playbackmanager.cpp:36
Base class for a playback manager.
Definition playbackmanager.h:59
Jellyfin::Model::PlayerStateClass::Value playbackState
Definition playbackmanager.h:85
void setSubtitleIndex(int newSubtitleIndex)
Definition playbackmanager.cpp:196
virtual void playItem(QSharedPointer< Model::Item > item)=0
Start playing the given item.
ApiClient * apiClient() const
Definition playbackmanager.cpp:131
void errorStringChanged(const QString &newErrorString)
void setQueueIndex(int index)
Definition playbackmanager.cpp:208
void setAudioIndex(int newAudioIndex)
Definition playbackmanager.cpp:185
QScopedPointer< PlaybackManagerPrivate > d_ptr
Definition playbackmanager.h:170
virtual bool hasNext() const =0
void errorChanged(Jellyfin::Model::PlaybackManagerErrorClass::Value newError)
virtual void goTo(int index)=0
Play the item at the index in the current playlist.
qint64 position
The position in ticks in the currently playing item.
Definition playbackmanager.h:68
QSharedPointer< Item > currentItem() const
Definition playbackmanager.cpp:141
void seekableChanged(bool newSeekable)
void playbackStateChanged(Jellyfin::Model::PlayerStateClass::Value newPlaybackState)
void swap(PlaybackManager &other)
Definition playbackmanager.cpp:156
virtual PlaybackManagerError error() const =0
void mediaStatusChanged(Jellyfin::Model::MediaStatusClass::Value newMediaStatus)
static const qint64 MS_TICK_FACTOR
Definition playbackmanager.h:131
bool hasVideo
Whether the currently playing item has video.
Definition playbackmanager.h:84
int queueIndex
Definition playbackmanager.h:87
bool seekable
Whether the playbackmanager is currently able to seek.
Definition playbackmanager.h:76
void hasPreviousChanged(bool newHasPrevious)
void positionChanged(qint64 newPosition)
void audioIndexChanged(int newAudioIndex)
void setApiClient(ApiClient *apiClient)
Definition playbackmanager.cpp:136
bool hasAudio
Whether the currently playing item has audio.
Definition playbackmanager.h:80
Playlist * queue() const
Definition playbackmanager.cpp:146
virtual void playItemInList(const QList< QSharedPointer< Model::Item > > &items, int index)=0
Set the playlist to the given playlist and start playing the item at the given index.
Jellyfin::Model::MediaStatusClass::Value mediaStatus
Definition playbackmanager.h:86
virtual const QString & errorString() const =0
int subtitleIndex
Definition playbackmanager.h:64
void setItem(QSharedPointer< Item > item)
Definition playbackmanager.cpp:202
void hasNextChanged(bool newHasNext)
void setResumePlayback(bool newResumePlayback)
Definition playbackmanager.cpp:174
void resumePlaybackChanged(bool newPlaybackChanged)
virtual void seek(qint64 pos)=0
bool resumePlayback
Definition playbackmanager.h:62
int audioIndex
Definition playbackmanager.h:63
virtual bool hasPrevious() const =0
void queueChanged(Jellyfin::Model::Playlist *newPlaylist)
void durationChanged(qint64 newDuration)
void subtitleIndexChanged(int newSubtitleIndex)
qint64 duration
The duration in ticks of the currently playing item.
Definition playbackmanager.h:72
virtual void playItemId(const QString &id)=0
Definition playbackmanager.cpp:167
Definition player.h:32
Value
Definition player.h:35
Abstract class for a player.
Definition player.h:69
Model of a playlist, a list of items that can be played.
Definition playlist.h:47
Controls playback for remote devices, such as other Jellyfin clients, over the network.
Definition playbackmanager.h:235
Definition mediaplayer2.h:20
Q_DECLARE_LOGGING_CATEGORY(playbackManager)