1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-11-24 18:15:16 +00:00

core: emit signals when playbackmanager changed

This commit is contained in:
Chris Josten 2023-01-11 23:55:53 +01:00
parent 7c6d8486de
commit 61a7eaf52e
2 changed files with 20 additions and 3 deletions

View file

@ -49,7 +49,7 @@ RemoteJellyfinPlayback::~RemoteJellyfinPlayback() {
}
PlayerState RemoteJellyfinPlayback::playbackState() const {
return m_lastSessionInfo.has_value()
return m_lastSessionInfo.has_value() && !m_lastSessionInfo->nowPlayingItem().isNull()
? m_lastSessionInfo.value().playState()->isPaused()
? PlayerState::Paused
: PlayerState::Playing
@ -149,6 +149,12 @@ void RemoteJellyfinPlayback::goTo(int index) {
void RemoteJellyfinPlayback::stop() {
sendPlaystateCommand(DTO::PlaystateCommand::Stop);
// Force update the UI, since the server will stop sending updates for some reason
/*if (m_lastSessionInfo.has_value()) {
m_lastSessionInfo->playState().clear();
m_lastSessionInfo->nowPlayingItem().clear();
onSessionInfoUpdated(m_sessionId, m_lastSessionInfo.value());
}*/
}
void RemoteJellyfinPlayback::seek(qint64 pos) {
@ -162,7 +168,6 @@ void RemoteJellyfinPlayback::onPositionTimerFired() {
void RemoteJellyfinPlayback::onSessionInfoUpdated(const QString &sessionId, const SessionInfo &sessionInfo) {
if (sessionId != m_sessionId) return;
qDebug() << "Session info updated for " << sessionId;
m_lastSessionInfo = sessionInfo;
if (m_lastSessionInfo->nowPlayingItem().isNull()) {
@ -174,7 +179,9 @@ void RemoteJellyfinPlayback::onSessionInfoUpdated(const QString &sessionId, cons
// Update current position and run timer if needed
if (m_lastSessionInfo.has_value()
&& !m_lastSessionInfo.value().playState().isNull()) {
&& !m_lastSessionInfo.value().playState().isNull()
// Apparently the nowPlayingItem should be null when the playback has stopped
&& !m_lastSessionInfo.value().nowPlayingItem().isNull()) {
m_position = m_lastSessionInfo.value().playState()->positionTicks().value_or(0) / PlaybackManager::MS_TICK_FACTOR;
if (!m_positionTimer->isActive() && !m_lastSessionInfo.value().playState()->isPaused()) {
m_positionTimer->start();

View file

@ -195,13 +195,21 @@ void PlaybackManager::setControllingSession(QSharedPointer<Model::ControllableSe
if (other != nullptr) {
connect(d->m_impl.data(), &Model::PlaybackManager::positionChanged, this, &PlaybackManager::positionChanged);
emit positionChanged(d->m_impl->position());
connect(d->m_impl.data(), &Model::PlaybackManager::durationChanged, this, &PlaybackManager::durationChanged);
emit durationChanged(d->m_impl->duration());
connect(d->m_impl.data(), &Model::PlaybackManager::hasNextChanged, this, &PlaybackManager::hasNextChanged);
emit hasNextChanged(d->m_impl->hasNext());
connect(d->m_impl.data(), &Model::PlaybackManager::hasPreviousChanged, this, &PlaybackManager::hasPreviousChanged);
emit hasPreviousChanged(d->m_impl->hasPrevious());
connect(d->m_impl.data(), &Model::PlaybackManager::seekableChanged, this, &PlaybackManager::seekableChanged);
emit seekableChanged(d->m_impl->seekable());
connect(d->m_impl.data(), &Model::PlaybackManager::queueIndexChanged, this, &PlaybackManager::queueIndexChanged);
emit queueIndexChanged(d->m_impl->queueIndex());
connect(d->m_impl.data(), &Model::PlaybackManager::itemChanged, this, &PlaybackManager::mediaPlayerItemChanged);
emit itemChanged();
connect(d->m_impl.data(), &Model::PlaybackManager::playbackStateChanged, this, &PlaybackManager::playbackStateChanged);
emit playbackStateChanged(d->m_impl->playbackState());
if (auto localImp = qobject_cast<Model::LocalPlaybackManager*>(d->m_impl.data())) {
connect(localImp, &Model::LocalPlaybackManager::streamUrlChanged, this, [this](const QUrl& newUrl){
@ -209,7 +217,9 @@ void PlaybackManager::setControllingSession(QSharedPointer<Model::ControllableSe
});
connect(localImp, &Model::LocalPlaybackManager::playMethodChanged, this, &PlaybackManager::playMethodChanged);
}
emit streamUrlChanged(streamUrl());
connect(d->m_impl.data(), &Model::PlaybackManager::mediaStatusChanged, this, &PlaybackManager::mediaStatusChanged);
emit mediaStatusChanged(d->m_impl->mediaStatus());
}
}