mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2024-11-22 09:15:18 +00:00
Improve PlaybackManager stability, added PlaybackBar
- PlaybackManager now takes ownership of set items - PlaybackManager can play items just by their itemId, avoids useless item creation on the QML side of things. - Allow calling Jellyfin::registerTypes with a different URI - Minor code cleanup
This commit is contained in:
parent
7e77abc173
commit
b699f6e74d
|
@ -10,7 +10,7 @@
|
||||||
#include "JellyfinQt/jellyfinplaybackmanager.h"
|
#include "JellyfinQt/jellyfinplaybackmanager.h"
|
||||||
|
|
||||||
namespace Jellyfin {
|
namespace Jellyfin {
|
||||||
void registerTypes();
|
void registerTypes(const char *uri = "nl.netsoj.chris.Jellyfin");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // JELLYFIN_H
|
#endif // JELLYFIN_H
|
||||||
|
|
|
@ -302,6 +302,7 @@ class Item : public RemoteData {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE explicit Item(QObject *parent = nullptr);
|
Q_INVOKABLE explicit Item(QObject *parent = nullptr);
|
||||||
|
Item(QString itemId, ApiClient *apiClient, QObject *parent = nullptr);
|
||||||
|
|
||||||
Q_PROPERTY(QString jellyfinId READ jellyfinId WRITE setJellyfinId NOTIFY jellyfinIdChanged)
|
Q_PROPERTY(QString jellyfinId READ jellyfinId WRITE setJellyfinId NOTIFY jellyfinIdChanged)
|
||||||
|
|
||||||
|
@ -473,7 +474,7 @@ protected:
|
||||||
QString getDataUrl() const override;
|
QString getDataUrl() const override;
|
||||||
bool canReload() const override;
|
bool canReload() const override;
|
||||||
|
|
||||||
QString m_id;
|
QString m_id = QStringLiteral("");
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QString m_originalTitle;
|
QString m_originalTitle;
|
||||||
QString m_serverId;
|
QString m_serverId;
|
||||||
|
|
|
@ -89,6 +89,12 @@ signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updatePlaybackInfo();
|
void updatePlaybackInfo();
|
||||||
|
/**
|
||||||
|
* @brief playItem Plays the item with the given id. This will construct the Jellyfin::Item internally
|
||||||
|
* and delete it later.
|
||||||
|
* @param itemId The id of the item to play.
|
||||||
|
*/
|
||||||
|
void playItem(const QString &itemId);
|
||||||
private slots:
|
private slots:
|
||||||
void mediaPlayerStateChanged(QMediaPlayer::State newState);
|
void mediaPlayerStateChanged(QMediaPlayer::State newState);
|
||||||
void mediaPlayerPositionChanged(qint64 position);
|
void mediaPlayerPositionChanged(qint64 position);
|
||||||
|
|
|
@ -19,19 +19,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
#include "JellyfinQt/jellyfin.h"
|
#include "JellyfinQt/jellyfin.h"
|
||||||
namespace Jellyfin {
|
namespace Jellyfin {
|
||||||
|
|
||||||
void registerTypes() {
|
void registerTypes(const char *uri) {
|
||||||
const char* QML_NAMESPACE = "nl.netsoj.chris.Jellyfin";
|
|
||||||
// Singletons are perhaps bad, but they are convenient :)
|
// Singletons are perhaps bad, but they are convenient :)
|
||||||
qmlRegisterSingletonType<Jellyfin::ApiClient>(QML_NAMESPACE, 1, 0, "ApiClient", [](QQmlEngine *eng, QJSEngine *js) {
|
qmlRegisterSingletonType<Jellyfin::ApiClient>(uri, 1, 0, "ApiClient", [](QQmlEngine *eng, QJSEngine *js) {
|
||||||
Q_UNUSED(eng)
|
Q_UNUSED(eng)
|
||||||
Q_UNUSED(js)
|
Q_UNUSED(js)
|
||||||
return dynamic_cast<QObject*>(new Jellyfin::ApiClient());
|
return dynamic_cast<QObject*>(new Jellyfin::ApiClient());
|
||||||
});
|
});
|
||||||
qmlRegisterType<Jellyfin::ServerDiscoveryModel>(QML_NAMESPACE, 1, 0, "ServerDiscoveryModel");
|
qmlRegisterType<Jellyfin::ServerDiscoveryModel>(uri, 1, 0, "ServerDiscoveryModel");
|
||||||
qmlRegisterType<Jellyfin::PlaybackManager>(QML_NAMESPACE, 1, 0, "PlaybackManager");
|
qmlRegisterType<Jellyfin::PlaybackManager>(uri, 1, 0, "PlaybackManager");
|
||||||
|
|
||||||
// API models
|
// API models
|
||||||
Jellyfin::registerModels(QML_NAMESPACE);
|
Jellyfin::registerModels(uri);
|
||||||
Jellyfin::registerSerializableJsonTypes(QML_NAMESPACE);
|
Jellyfin::registerSerializableJsonTypes(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,6 @@ ApiClient::ApiClient(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_webSocket(new WebSocket(this)) {
|
m_webSocket(new WebSocket(this)) {
|
||||||
m_deviceName = QHostInfo::localHostName();
|
m_deviceName = QHostInfo::localHostName();
|
||||||
uint uuid1 = qHash(m_deviceName);
|
|
||||||
uint uuid2 = qHash(QSysInfo::productVersion());
|
|
||||||
m_deviceId = QUuid::createUuid().toString(); // TODO: make this not random?
|
m_deviceId = QUuid::createUuid().toString(); // TODO: make this not random?
|
||||||
m_credManager = CredentialsManager::newInstance(this);
|
m_credManager = CredentialsManager::newInstance(this);
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ void JsonSerializable::deserialize(const QJsonObject &jObj) {
|
||||||
QMetaProperty realProp = obj->property(obj->indexOfProperty(prop.name() + 8));
|
QMetaProperty realProp = obj->property(obj->indexOfProperty(prop.name() + 8));
|
||||||
if (!realProp.write(this, jsonToVariant(prop, val, jObj))) {
|
if (!realProp.write(this, jsonToVariant(prop, val, jObj))) {
|
||||||
qDebug() << "Write to " << prop.name() << "failed";
|
qDebug() << "Write to " << prop.name() << "failed";
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,6 +328,14 @@ Item::Item(QObject *parent) : RemoteData(parent) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item::Item(QString id, ApiClient *apiClient, QObject *parent)
|
||||||
|
: RemoteData(parent), m_id(id) {
|
||||||
|
connect(this, &RemoteData::apiClientChanged, this, [this](ApiClient *newApiClient) {
|
||||||
|
connect(newApiClient, &ApiClient::userDataChanged, this, &Item::onUserDataChanged);
|
||||||
|
});
|
||||||
|
setApiClient(apiClient);
|
||||||
|
}
|
||||||
|
|
||||||
QString Item::getDataUrl() const {
|
QString Item::getDataUrl() const {
|
||||||
return QString("/Users/") + m_apiClient->userId() + "/Items/" + m_id;
|
return QString("/Users/") + m_apiClient->userId() + "/Items/" + m_id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,13 @@ void PlaybackManager::fetchStreamUrl() {
|
||||||
|
|
||||||
void PlaybackManager::setItem(Item *newItem) {
|
void PlaybackManager::setItem(Item *newItem) {
|
||||||
if (m_mediaPlayer != nullptr) m_mediaPlayer->stop();
|
if (m_mediaPlayer != nullptr) m_mediaPlayer->stop();
|
||||||
|
|
||||||
|
// If we own the item, delete it.
|
||||||
|
if (m_item != nullptr && m_item->parent() == this) {
|
||||||
|
m_item->deleteLater();
|
||||||
|
}
|
||||||
this->m_item = newItem;
|
this->m_item = newItem;
|
||||||
|
emit itemChanged(newItem);
|
||||||
// Don't try to start fetching when we're not completely parsed yet.
|
// Don't try to start fetching when we're not completely parsed yet.
|
||||||
if (m_qmlIsParsingComponent) return;
|
if (m_qmlIsParsingComponent) return;
|
||||||
|
|
||||||
|
@ -110,6 +116,16 @@ void PlaybackManager::setItem(Item *newItem) {
|
||||||
// Deinitialize the streamUrl
|
// Deinitialize the streamUrl
|
||||||
setStreamUrl("");
|
setStreamUrl("");
|
||||||
if (newItem != nullptr) {
|
if (newItem != nullptr) {
|
||||||
|
if (newItem->parent() != this) {
|
||||||
|
// The new item may outlive the lifetime of the element it was created on. In the Sailfish
|
||||||
|
// application for example, the player is given an Jellyfin::Item that sits on a Page on a PageStack.
|
||||||
|
// As soon as the user pops the Page from the PageStack, newItem would be destroyed. Therefore, we
|
||||||
|
// take ownership of the given newItem, as this object will usually exist throughout the lifetime of
|
||||||
|
// the application. A better solution would be to create a copy of the newItem, but no way I'm going
|
||||||
|
// to create an handwritten copy of that.
|
||||||
|
QQmlEngine::setObjectOwnership(newItem, QQmlEngine::ObjectOwnership::CppOwnership);
|
||||||
|
newItem->setParent(this);
|
||||||
|
}
|
||||||
if (m_item->status() == RemoteData::Ready) {
|
if (m_item->status() == RemoteData::Ready) {
|
||||||
fetchStreamUrl();
|
fetchStreamUrl();
|
||||||
} else {
|
} else {
|
||||||
|
@ -192,6 +208,11 @@ void PlaybackManager::updatePlaybackInfo() {
|
||||||
postPlaybackInfo(Progress);
|
postPlaybackInfo(Progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlaybackManager::playItem(const QString &itemId) {
|
||||||
|
Item *newItem = new Item(itemId, m_apiClient, this);
|
||||||
|
setItem(newItem);
|
||||||
|
}
|
||||||
|
|
||||||
void PlaybackManager::postPlaybackInfo(PlaybackInfoType type) {
|
void PlaybackManager::postPlaybackInfo(PlaybackInfoType type) {
|
||||||
QJsonObject root;
|
QJsonObject root;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ set(sailfin_QML_SOURCES
|
||||||
qml/components/LibraryItemDelegate.qml
|
qml/components/LibraryItemDelegate.qml
|
||||||
qml/components/MoreSection.qml
|
qml/components/MoreSection.qml
|
||||||
qml/components/PlainLabel.qml
|
qml/components/PlainLabel.qml
|
||||||
|
qml/components/PlaybackBar.qml
|
||||||
qml/components/PlayToolbar.qml
|
qml/components/PlayToolbar.qml
|
||||||
qml/components/RemoteImage.qml
|
qml/components/RemoteImage.qml
|
||||||
qml/components/Shim.qml
|
qml/components/Shim.qml
|
||||||
|
|
106
sailfish/qml/components/PlaybackBar.qml
Normal file
106
sailfish/qml/components/PlaybackBar.qml
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
Sailfin: a Jellyfin client written using Qt
|
||||||
|
Copyright (C) 2021 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
import QtQuick 2.6
|
||||||
|
import QtQuick.Layouts 1.1
|
||||||
|
import QtMultimedia 5.6
|
||||||
|
import Sailfish.Silica 1.0
|
||||||
|
|
||||||
|
import nl.netsoj.chris.Jellyfin 1.0
|
||||||
|
|
||||||
|
import "../"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* +---+--------------------------------------+
|
||||||
|
* |\ /| +---+ |
|
||||||
|
* | \ / | Media title | | |
|
||||||
|
* | X | | ⏸︎| |
|
||||||
|
* | / \ | Artist 1, artist 2 | | |
|
||||||
|
* |/ \| +---+ |
|
||||||
|
* +-----+------------------------------------+
|
||||||
|
*/
|
||||||
|
DockedPanel {
|
||||||
|
height: content.height
|
||||||
|
width: parent.width
|
||||||
|
property PlaybackManager manager
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: content
|
||||||
|
width: parent.width
|
||||||
|
height: Theme.itemSizeLarge
|
||||||
|
RemoteImage {
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: content.height
|
||||||
|
blurhash: manager.item.imageBlurHashes["Primary"][manager.item.imageTags["Primary"]]
|
||||||
|
source: Utils.itemImageUrl(ApiClient.baseUrl, manager.item, "Primary", {"maxWidth": parent.width})
|
||||||
|
fillMode: Image.PreserveAspectCrop
|
||||||
|
}
|
||||||
|
Item { height: 1; Layout.preferredWidth: Theme.paddingMedium; } // Padding
|
||||||
|
Column {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||||
|
Layout.minimumWidth: 10 * Theme.pixelRatio
|
||||||
|
Label {
|
||||||
|
text: manager.item == null ? qsTr("No media selected") : manager.item.name
|
||||||
|
width: parent.width
|
||||||
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
|
truncationMode: TruncationMode.Fade
|
||||||
|
}
|
||||||
|
Label {
|
||||||
|
text: {
|
||||||
|
if (manager.item == null) return qsTr("Play some media!")
|
||||||
|
console.log(manager.item.type)
|
||||||
|
switch(manager.item.type) {
|
||||||
|
case "Audio":
|
||||||
|
return manager.item.artists.join(", ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
width: parent.width
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
truncationMode: TruncationMode.Fade
|
||||||
|
color: highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Item { height: 1; Layout.preferredWidth: Theme.paddingMedium; } // Padding
|
||||||
|
IconButton {
|
||||||
|
id: playButton
|
||||||
|
Layout.preferredHeight: Theme.iconSizeMedium
|
||||||
|
Layout.preferredWidth: Theme.iconSizeMedium
|
||||||
|
icon.source: appWindow.mediaPlayer.playbackState === MediaPlayer.PlayingState
|
||||||
|
? "image://theme/icon-m-pause" : "image://theme/icon-m-play"
|
||||||
|
onClicked: appWindow.mediaPlayer.playbackState === MediaPlayer.PlayingState
|
||||||
|
? appWindow.mediaPlayer.pause()
|
||||||
|
: appWindow.mediaPlayer.play()
|
||||||
|
}
|
||||||
|
Item { height: 1; Layout.preferredWidth: Theme.paddingMedium; } // Padding
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressBar {
|
||||||
|
anchors.verticalCenter: parent.top
|
||||||
|
width: parent.width
|
||||||
|
leftMargin: Theme.itemSizeLarge
|
||||||
|
rightMargin: 0
|
||||||
|
minimumValue: 0
|
||||||
|
value: appWindow.mediaPlayer.position
|
||||||
|
maximumValue: appWindow.mediaPlayer.duration
|
||||||
|
indeterminate: [MediaPlayer.Loading, MediaPlayer.Buffering].indexOf(appWindow.mediaPlayer.status) >= 0
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,6 +43,18 @@ ApplicationWindow {
|
||||||
// Bad way to implement settings, but it'll do for now.
|
// Bad way to implement settings, but it'll do for now.
|
||||||
property bool showDebugInfo: false
|
property bool showDebugInfo: false
|
||||||
|
|
||||||
|
property bool _hidePlaybackBar: false
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: pageStack
|
||||||
|
onCurrentPageChanged: {
|
||||||
|
_hidePlaybackBar = "__videoPlaybackPage" in pageStack.currentPage
|
||||||
|
console.log("Current page changed: " + _hidePlaybackBar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bottomMargin: playbackBar.visibleSize
|
||||||
|
|
||||||
//FIXME: proper error handling
|
//FIXME: proper error handling
|
||||||
Connections {
|
Connections {
|
||||||
target: ApiClient
|
target: ApiClient
|
||||||
|
@ -119,7 +131,9 @@ ApplicationWindow {
|
||||||
preventBlanking: _mediaPlayer.playbackState == MediaPlayer.PlayingState && _mediaPlayer.hasVideo
|
preventBlanking: _mediaPlayer.playbackState == MediaPlayer.PlayingState && _mediaPlayer.hasVideo
|
||||||
}
|
}
|
||||||
|
|
||||||
DockedPanel {
|
PlaybackBar {
|
||||||
|
id: playbackBar
|
||||||
|
open: !_hidePlaybackBar//_mediaPlayer.playbackState != MediaPlayer.StoppedState
|
||||||
|
manager: _playbackManager
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import nl.netsoj.chris.Jellyfin 1.0
|
||||||
|
|
||||||
Page {
|
Page {
|
||||||
id: videoPage
|
id: videoPage
|
||||||
|
property bool __videoPlaybackPage: true
|
||||||
property JellyfinItem itemData
|
property JellyfinItem itemData
|
||||||
property int audioTrack
|
property int audioTrack
|
||||||
property int subtitleTrack
|
property int subtitleTrack
|
||||||
|
|
|
@ -78,8 +78,7 @@ BaseDetailPage {
|
||||||
artists: model.artists
|
artists: model.artists
|
||||||
duration: model.runTimeTicks
|
duration: model.runTimeTicks
|
||||||
indexNumber: model.indexNumber
|
indexNumber: model.indexNumber
|
||||||
onClicked: window.playbackManager.item = Qt.createQmlObject("import nl.netsoj.chris.Jellyfin 1.0;"
|
onClicked: window.playbackManager.playItem(model.id)
|
||||||
+ "JellyfinItem { jellyfinId: \"" + model.id + "\"; apiClient: ApiClient; }", songDelegate, "nonexistent.qml");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VerticalScrollDecorator {}
|
VerticalScrollDecorator {}
|
||||||
|
|
Loading…
Reference in a new issue