Controls for playback state

This commit is contained in:
Kovid Goyal 2023-01-29 10:40:22 +05:30
parent 356af928ac
commit e006a23b70
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -470,6 +470,25 @@ class Synthesizer {
synth.Options().AudioPitch(val); synth.Options().AudioPitch(val);
} }
void pause() const {
player.Pause();
}
void play() const {
player.Play();
}
bool toggle() const {
switch (player.PlaybackSession().PlaybackState()) {
case MediaPlaybackState::Playing: pause(); return true;
case MediaPlaybackState::Paused: play(); return true;
default: return false;
}
}
MediaPlaybackState playback_state() const {
return player.PlaybackSession().PlaybackState();
}
}; };
@ -795,6 +814,18 @@ handle_stdin_message(winrt::hstring const &&msg) {
} catch(...) { } } catch(...) { }
return 0; return 0;
} }
else if (command == L"play") {
sx.play();
output(cmd_id, "play", {{"playback_state", sx.playback_state()}});
}
else if (command == L"pause") {
sx.play();
output(cmd_id, "pause", {{"playback_state", sx.playback_state()}});
}
else if (command == L"state") {
sx.play();
output(cmd_id, "state", {{"playback_state", sx.playback_state()}});
}
else if (command == L"echo") { else if (command == L"echo") {
output(cmd_id, "echo", {{"msg", join(parts)}}); output(cmd_id, "echo", {{"msg", join(parts)}});
} }