mpriscontrolplugin-win: add support for loopStatus and shuffle control
This commit is contained in:
parent
a59ea0e9b8
commit
ee19722eea
1 changed files with 41 additions and 1 deletions
|
@ -86,11 +86,30 @@ void MprisControlPlugin::sendPlaybackInfo(std::variant<NetworkPacket, QString> c
|
||||||
auto playbackInfo = player.GetPlaybackInfo();
|
auto playbackInfo = player.GetPlaybackInfo();
|
||||||
auto playbackControls = playbackInfo.Controls();
|
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("isPlaying"), playbackInfo.PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing);
|
||||||
np.set(QStringLiteral("canPause"), playbackControls.IsPauseEnabled());
|
np.set(QStringLiteral("canPause"), playbackControls.IsPauseEnabled());
|
||||||
np.set(QStringLiteral("canPlay"), playbackControls.IsPlayEnabled());
|
np.set(QStringLiteral("canPlay"), playbackControls.IsPlayEnabled());
|
||||||
np.set(QStringLiteral("canGoNext"), playbackControls.IsNextEnabled());
|
np.set(QStringLiteral("canGoNext"), playbackControls.IsNextEnabled());
|
||||||
np.set(QStringLiteral("canGoPrevious"), playbackControls.IsPreviousEnabled());
|
np.set(QStringLiteral("canGoPrevious"), playbackControls.IsPreviousEnabled());
|
||||||
|
np.set(QStringLiteral("canSeek"), playbackControls.IsPlaybackPositionEnabled());
|
||||||
|
np.set(QStringLiteral("shuffle"), playbackInfo.IsShuffleActive().Value());
|
||||||
|
np.set(QStringLiteral("loopStatus"), loopStatus);
|
||||||
|
|
||||||
sendTimelineProperties(np, player);
|
sendTimelineProperties(np, player);
|
||||||
|
|
||||||
|
@ -106,7 +125,9 @@ void MprisControlPlugin::sendTimelineProperties(std::variant<NetworkPacket, QStr
|
||||||
auto timelineProperties = player.GetTimelineProperties();
|
auto timelineProperties = player.GetTimelineProperties();
|
||||||
|
|
||||||
if(!lengthOnly){
|
if(!lengthOnly){
|
||||||
np.set(QStringLiteral("canSeek"), timelineProperties.MinSeekTime() != timelineProperties.MaxSeekTime());
|
const auto playbackInfo = player.GetPlaybackInfo();
|
||||||
|
const auto playbackControls = playbackInfo.Controls();
|
||||||
|
np.set(QStringLiteral("canSeek"), playbackControls.IsPlaybackPositionEnabled());
|
||||||
np.set(QStringLiteral("pos"), std::chrono::duration_cast<std::chrono::milliseconds>(timelineProperties.Position() - timelineProperties.StartTime()).count());
|
np.set(QStringLiteral("pos"), std::chrono::duration_cast<std::chrono::milliseconds>(timelineProperties.Position() - timelineProperties.StartTime()).count());
|
||||||
}
|
}
|
||||||
np.set(QStringLiteral("length"), std::chrono::duration_cast<std::chrono::milliseconds>(timelineProperties.EndTime() - timelineProperties.StartTime()).count());
|
np.set(QStringLiteral("length"), std::chrono::duration_cast<std::chrono::milliseconds>(timelineProperties.EndTime() - timelineProperties.StartTime()).count());
|
||||||
|
@ -292,6 +313,25 @@ bool MprisControlPlugin::receivePacket(const NetworkPacket &np)
|
||||||
player.TryChangePlaybackPositionAsync((player.GetTimelineProperties().StartTime() + position).count()).get();
|
player.TryChangePlaybackPositionAsync((player.GetTimelineProperties().StartTime() + position).count()).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (np.has(QStringLiteral("setShuffle")))
|
||||||
|
{
|
||||||
|
player.TryChangeShuffleActiveAsync(np.get<bool>(QStringLiteral("setShuffle")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (np.has(QStringLiteral("setLoopStatus")))
|
||||||
|
{
|
||||||
|
QString loopStatus = np.get<QString>(QStringLiteral("setLoopStatus"));
|
||||||
|
enum class winrt::Windows::Media::MediaPlaybackAutoRepeatMode loopStatusEnumVal;
|
||||||
|
if (loopStatus == QStringLiteral("Track")) {
|
||||||
|
loopStatusEnumVal = Windows::Media::MediaPlaybackAutoRepeatMode::Track;
|
||||||
|
} else if (loopStatus == QStringLiteral("Playlist")) {
|
||||||
|
loopStatusEnumVal = Windows::Media::MediaPlaybackAutoRepeatMode::List;
|
||||||
|
} else {
|
||||||
|
loopStatusEnumVal = Windows::Media::MediaPlaybackAutoRepeatMode::None;
|
||||||
|
}
|
||||||
|
player.TryChangeAutoRepeatModeAsync(loopStatusEnumVal);
|
||||||
|
}
|
||||||
|
|
||||||
//Send something read from the mpris interface
|
//Send something read from the mpris interface
|
||||||
NetworkPacket answer(PACKET_TYPE_MPRIS);
|
NetworkPacket answer(PACKET_TYPE_MPRIS);
|
||||||
answer.set(QStringLiteral("player"), name);
|
answer.set(QStringLiteral("player"), name);
|
||||||
|
|
Loading…
Reference in a new issue