From d71af0134e864f72c0dab6f170c5279f8cadd0be Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Thu, 24 Jun 2021 15:29:43 +0530 Subject: [PATCH] mpriscontrolplugin-win: add nullptr check for autoRepeatMode and isShuffleActive --- .../mpriscontrol/mpriscontrolplugin-win.cpp | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/plugins/mpriscontrol/mpriscontrolplugin-win.cpp b/plugins/mpriscontrol/mpriscontrolplugin-win.cpp index 1150ab02b..2795068a4 100644 --- a/plugins/mpriscontrol/mpriscontrolplugin-win.cpp +++ b/plugins/mpriscontrol/mpriscontrolplugin-win.cpp @@ -86,30 +86,36 @@ void MprisControlPlugin::sendPlaybackInfo(std::variant c auto playbackInfo = player.GetPlaybackInfo(); auto playbackControls = playbackInfo.Controls(); - QString loopStatus; - switch(playbackInfo.AutoRepeatMode().Value()) { - case Windows::Media::MediaPlaybackAutoRepeatMode::List: { - loopStatus = QStringLiteral("Playlist"); - break; - } - case Windows::Media::MediaPlaybackAutoRepeatMode::Track: { - loopStatus = QStringLiteral("Track"); - break; - } - default: { - loopStatus = QStringLiteral("None"); - break; - } - } - np.set(QStringLiteral("isPlaying"), playbackInfo.PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing); np.set(QStringLiteral("canPause"), playbackControls.IsPauseEnabled()); np.set(QStringLiteral("canPlay"), playbackControls.IsPlayEnabled()); np.set(QStringLiteral("canGoNext"), playbackControls.IsNextEnabled()); np.set(QStringLiteral("canGoPrevious"), playbackControls.IsPreviousEnabled()); np.set(QStringLiteral("canSeek"), playbackControls.IsPlaybackPositionEnabled()); - np.set(QStringLiteral("shuffle"), playbackInfo.IsShuffleActive().Value()); - np.set(QStringLiteral("loopStatus"), loopStatus); + + if (playbackInfo.IsShuffleActive()) { + const bool shuffleStatus = playbackInfo.IsShuffleActive().Value(); + np.set(QStringLiteral("shuffle"), shuffleStatus); + } + + if (playbackInfo.AutoRepeatMode()) { + QString loopStatus; + switch(playbackInfo.AutoRepeatMode().Value()) { + case Windows::Media::MediaPlaybackAutoRepeatMode::List: { + loopStatus = QStringLiteral("Playlist"); + break; + } + case Windows::Media::MediaPlaybackAutoRepeatMode::Track: { + loopStatus = QStringLiteral("Track"); + break; + } + default: { + loopStatus = QStringLiteral("None"); + break; + } + } + np.set(QStringLiteral("loopStatus"), loopStatus); + } sendTimelineProperties(np, player);