1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-11-14 13:35:17 +00:00
harbour-sailfin/core/include/JellyfinQt/model/remotejellyfinplayback.h
Chris Josten 6ed623d0f8 core/RemoteJellyfinPlaybackManager: keep queue in sync
The playback queue is now kept in sync with the playback queue of the
remote jellyfin instance the manager is controlling.

Some additional guards were added in place in the shuffle and playlist
algorithm, since the situation can occur where the now playing index
falls outside of the playing playlist. This happens because when the
an playlist update is received, we need to do another HTTP request
before we know which items are in the queue, while the now playing index
has been updated.

This is a not-optimal way to fix that, but it works well enough for now
and a better solution can be implemented later. (Hello, person in the
future reading the git blame output!)
2024-01-02 00:19:13 +01:00

102 lines
3.5 KiB
C++

/*
* Sailfin: a Jellyfin client written using Qt
* Copyright (C) 2023 Chris Josten and the Sailfin Contributors.
*
* 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
*/
#ifndef JELLYFIN_MODEL_REMOTEJELLYFINPLAYBACK_H
#define JELLYFIN_MODEL_REMOTEJELLYFINPLAYBACK_H
#include <JellyfinQt/dto/generalcommandtype.h>
#include <JellyfinQt/dto/playcommand.h>
#include <JellyfinQt/dto/playstatecommand.h>
#include <JellyfinQt/dto/sessioninfo.h>
#include <JellyfinQt/model/playbackmanager.h>
#include <JellyfinQt/support/loader.h>
#include <QJsonObject>
#include <QSharedPointer>
#include <QTimer>
#include <optional>
namespace Jellyfin {
class ApiClient;
namespace Model {
class RemoteJellyfinPlayback : public PlaybackManager {
public:
RemoteJellyfinPlayback(ApiClient &apiClient, QString sessionId, QObject *parent = nullptr);
virtual ~RemoteJellyfinPlayback();
// PlaybackManager
PlayerState playbackState() const override;
MediaStatus mediaStatus() const override;
bool hasNext() const override;
bool hasPrevious() const override;
PlaybackManagerError error() const override;
const QString &errorString() const override;
qint64 position() const override;
qint64 duration() const override;
bool seekable() const override;
bool hasAudio() const override;
bool hasVideo() const override;
void playItem(QSharedPointer<Item> item) override;
void playItemInList(const QList<QSharedPointer<Item> > &items, int index) override;
public slots:
void pause() override;
void play() override;
void playItemId(const QString &id) override;
void previous() override;
void next() override;
void goTo(int index) override;
void stop() override;
void seek(qint64 pos) override;
private slots:
void onPositionTimerFired();
void onSessionInfoUpdated(const QString &sessionId, const DTO::SessionInfo &sessionInfo);
private:
void sendPlaystateCommand(DTO::PlaystateCommand command, qint64 seekTicks = -1);
void sendGeneralCommand(DTO::GeneralCommandType command, QJsonObject arguments = QJsonObject());
void sendCommand(Support::LoaderBase *loader);
void playItemInList(const QStringList &items, int index, qint64 resumeTicks = -1);
/**
* @brief isQueueSame Checks if the items in the list are the same as in the queue
* @param items The item ids to compare to the queue
* @return True if the same, otherwise false
*/
bool isQueueSame(QList<QueueItem> itemIds);
/**
* Updates the now playing queue, with the given items
* @param itemIds The item ids to load
*/
void updateQueue(QList<QueueItem> itemIds);
ApiClient &m_apiClient;
QString m_sessionId;
std::optional<DTO::SessionInfo> m_lastSessionInfo;
QTimer *m_positionTimer;
qint64 m_position = 0;
};
} // NS Model
} // NS Jellyfin
#endif // JELLYFIN_MODEL_REMOTEJELLYFINPLAYBACK_H