diff --git a/core/src/model/remotejellyfinplayback.cpp b/core/src/model/remotejellyfinplayback.cpp index 1734423..6e673a7 100644 --- a/core/src/model/remotejellyfinplayback.cpp +++ b/core/src/model/remotejellyfinplayback.cpp @@ -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(); diff --git a/core/src/viewmodel/playbackmanager.cpp b/core/src/viewmodel/playbackmanager.cpp index b1912ef..d8e4303 100644 --- a/core/src/viewmodel/playbackmanager.cpp +++ b/core/src/viewmodel/playbackmanager.cpp @@ -195,13 +195,21 @@ void PlaybackManager::setControllingSession(QSharedPointerm_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(d->m_impl.data())) { connect(localImp, &Model::LocalPlaybackManager::streamUrlChanged, this, [this](const QUrl& newUrl){ @@ -209,7 +217,9 @@ void PlaybackManager::setControllingSession(QSharedPointerm_impl.data(), &Model::PlaybackManager::mediaStatusChanged, this, &PlaybackManager::mediaStatusChanged); + emit mediaStatusChanged(d->m_impl->mediaStatus()); } }