2020-09-27 18:38:33 +00:00
|
|
|
/*
|
|
|
|
Sailfin: a Jellyfin client written using Qt
|
|
|
|
Copyright (C) 2020 Chris Josten
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2020-09-25 12:46:39 +00:00
|
|
|
#ifndef JELLYFIN_MEDIA_SOURCE_H
|
|
|
|
#define JELLYFIN_MEDIA_SOURCE_H
|
|
|
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QObject>
|
2020-10-01 19:45:34 +00:00
|
|
|
#include <QVariant>
|
2020-09-25 12:46:39 +00:00
|
|
|
|
|
|
|
#include <QUrlQuery>
|
|
|
|
|
|
|
|
#include <QtMultimedia/QMediaPlayer>
|
|
|
|
|
|
|
|
|
|
|
|
#include "jellyfinapiclient.h"
|
|
|
|
|
|
|
|
namespace Jellyfin {
|
|
|
|
|
2020-10-08 01:00:08 +00:00
|
|
|
class PlaybackManager : public QObject {
|
2020-09-25 12:46:39 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-10-01 19:45:34 +00:00
|
|
|
enum PlayMethod {
|
|
|
|
Transcode,
|
|
|
|
Stream,
|
|
|
|
DirectPlay
|
|
|
|
};
|
|
|
|
Q_ENUM(PlayMethod)
|
|
|
|
|
2020-10-08 01:00:08 +00:00
|
|
|
explicit PlaybackManager(QObject *parent = nullptr);
|
2020-09-25 12:46:39 +00:00
|
|
|
Q_PROPERTY(ApiClient *apiClient MEMBER m_apiClient)
|
|
|
|
Q_PROPERTY(QString itemId READ itemId WRITE setItemId NOTIFY itemIdChanged)
|
|
|
|
Q_PROPERTY(QString streamUrl READ streamUrl NOTIFY streamUrlChanged)
|
|
|
|
Q_PROPERTY(bool autoOpen MEMBER m_autoOpen NOTIFY autoOpenChanged)
|
2020-09-25 15:14:44 +00:00
|
|
|
Q_PROPERTY(int audioIndex MEMBER m_audioIndex NOTIFY audioIndexChanged)
|
|
|
|
Q_PROPERTY(int subtitleIndex MEMBER m_subtitleIndex NOTIFY subtitleIndexChanged)
|
2020-10-01 19:45:34 +00:00
|
|
|
Q_PROPERTY(qint64 position MEMBER m_position WRITE setPosition NOTIFY positionChanged)
|
|
|
|
Q_PROPERTY(QMediaPlayer::State state READ state WRITE setState NOTIFY stateChanged)
|
2020-09-25 12:46:39 +00:00
|
|
|
|
|
|
|
QString itemId() const { return m_itemId; }
|
|
|
|
void setItemId(const QString &newItemId);
|
|
|
|
|
2020-10-01 19:45:34 +00:00
|
|
|
QMediaPlayer::State state() const { return m_state; }
|
|
|
|
void setState(QMediaPlayer::State newState);
|
|
|
|
|
|
|
|
void setPosition(qint64 position);
|
|
|
|
|
2020-09-25 12:46:39 +00:00
|
|
|
QString streamUrl() const { return m_streamUrl; }
|
|
|
|
signals:
|
|
|
|
void itemIdChanged(const QString &newItemId);
|
|
|
|
void streamUrlChanged(const QString &newStreamUrl);
|
|
|
|
void autoOpenChanged(bool autoOpen);
|
2020-09-25 15:14:44 +00:00
|
|
|
void audioIndexChanged(int audioIndex);
|
|
|
|
void subtitleIndexChanged(int subtitleIndex);
|
2020-10-01 19:45:34 +00:00
|
|
|
void positionChanged(qint64 position);
|
|
|
|
void stateChanged(QMediaPlayer::State state);
|
2020-09-25 12:46:39 +00:00
|
|
|
|
|
|
|
public slots:
|
2020-10-01 19:45:34 +00:00
|
|
|
void updatePlaybackInfo();
|
2020-09-25 12:46:39 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-01 19:45:34 +00:00
|
|
|
QTimer m_updateTimer;
|
2020-09-25 12:46:39 +00:00
|
|
|
ApiClient *m_apiClient = nullptr;
|
|
|
|
QString m_itemId;
|
|
|
|
QString m_streamUrl;
|
|
|
|
QString m_playSessionId;
|
2020-09-25 15:14:44 +00:00
|
|
|
int m_audioIndex = 0;
|
|
|
|
int m_subtitleIndex = -1;
|
2020-10-01 19:45:34 +00:00
|
|
|
qint64 m_position = 0;
|
|
|
|
qint64 m_stopPosition = 0;
|
|
|
|
PlayMethod m_playMethod;
|
|
|
|
QMediaPlayer::State m_state = QMediaPlayer::StoppedState;
|
2020-09-25 15:14:44 +00:00
|
|
|
|
2020-09-25 12:46:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Whether to automatically open the livestream of the item;
|
|
|
|
*/
|
|
|
|
bool m_autoOpen = false;
|
|
|
|
|
|
|
|
void fetchStreamUrl();
|
|
|
|
void setStreamUrl(const QString &streamUrl);
|
2020-10-01 19:45:34 +00:00
|
|
|
|
|
|
|
// Factor to multiply with when converting from milliseconds to ticks.
|
|
|
|
const int MS_TICK_FACTOR = 10000;
|
|
|
|
|
|
|
|
enum PlaybackInfoType { Started, Stopped, Progress };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Posts the playback information
|
|
|
|
*/
|
|
|
|
void postPlaybackInfo(PlaybackInfoType type);
|
2020-09-25 12:46:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // JELLYFIN_MEDIA_SOURCE_H
|