mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added initial support of seeking to SMC class.
This commit is contained in:
parent
1cfbf24635
commit
13c70a9ce9
1 changed files with 32 additions and 3 deletions
|
@ -39,12 +39,15 @@ SystemMediaControlsManager::SystemMediaControlsManager(
|
||||||
}
|
}
|
||||||
const auto type = AudioMsgId::Type::Song;
|
const auto type = AudioMsgId::Type::Song;
|
||||||
|
|
||||||
|
using TrackState = Media::Player::TrackState;
|
||||||
const auto mediaPlayer = Media::Player::instance();
|
const auto mediaPlayer = Media::Player::instance();
|
||||||
|
|
||||||
|
auto trackFilter = rpl::filter([=](const TrackState &state) {
|
||||||
|
return (state.id.type() == type);
|
||||||
|
});
|
||||||
|
|
||||||
mediaPlayer->updatedNotifier(
|
mediaPlayer->updatedNotifier(
|
||||||
) | rpl::filter([=](const Media::Player::TrackState &state) {
|
) | trackFilter | rpl::map([=](const TrackState &state) {
|
||||||
return state.id.type() == type;
|
|
||||||
}) | rpl::map([=](const Media::Player::TrackState &state) {
|
|
||||||
using namespace Media::Player;
|
using namespace Media::Player;
|
||||||
if (IsStoppedOrStopping(state.state)) {
|
if (IsStoppedOrStopping(state.state)) {
|
||||||
return PlaybackStatus::Stopped;
|
return PlaybackStatus::Stopped;
|
||||||
|
@ -57,6 +60,24 @@ SystemMediaControlsManager::SystemMediaControlsManager(
|
||||||
_controls->setPlaybackStatus(status);
|
_controls->setPlaybackStatus(status);
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
|
|
||||||
|
if (_controls->seekingSupported()) {
|
||||||
|
mediaPlayer->updatedNotifier(
|
||||||
|
) | trackFilter | rpl::map([=](const TrackState &state) {
|
||||||
|
return state.position;
|
||||||
|
}) | rpl::distinct_until_changed(
|
||||||
|
) | rpl::start_with_next([=](int position) {
|
||||||
|
_controls->setPosition(position);
|
||||||
|
}, _lifetime);
|
||||||
|
|
||||||
|
mediaPlayer->updatedNotifier(
|
||||||
|
) | trackFilter | rpl::map([=](const TrackState &state) {
|
||||||
|
return state.length;
|
||||||
|
}) | rpl::distinct_until_changed(
|
||||||
|
) | rpl::start_with_next([=](int length) {
|
||||||
|
_controls->setDuration(length);
|
||||||
|
}, _lifetime);
|
||||||
|
}
|
||||||
|
|
||||||
rpl::merge(
|
rpl::merge(
|
||||||
mediaPlayer->stops(type) | rpl::map_to(false),
|
mediaPlayer->stops(type) | rpl::map_to(false),
|
||||||
mediaPlayer->startsPlay(type) | rpl::map_to(true)
|
mediaPlayer->startsPlay(type) | rpl::map_to(true)
|
||||||
|
@ -135,6 +156,7 @@ SystemMediaControlsManager::SystemMediaControlsManager(
|
||||||
_controls->commandRequests(
|
_controls->commandRequests(
|
||||||
) | rpl::start_with_next([=](Command command) {
|
) | rpl::start_with_next([=](Command command) {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
|
case Command::PlayPause: mediaPlayer->playPause(type); break;
|
||||||
case Command::Play: mediaPlayer->play(type); break;
|
case Command::Play: mediaPlayer->play(type); break;
|
||||||
case Command::Pause: mediaPlayer->pause(type); break;
|
case Command::Pause: mediaPlayer->pause(type); break;
|
||||||
case Command::Next: mediaPlayer->next(type); break;
|
case Command::Next: mediaPlayer->next(type); break;
|
||||||
|
@ -143,6 +165,13 @@ SystemMediaControlsManager::SystemMediaControlsManager(
|
||||||
}
|
}
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
|
|
||||||
|
if (_controls->seekingSupported()) {
|
||||||
|
_controls->seekRequests(
|
||||||
|
) | rpl::start_with_next([=](float64 progress) {
|
||||||
|
mediaPlayer->finishSeeking(type, progress);
|
||||||
|
}, _lifetime);
|
||||||
|
}
|
||||||
|
|
||||||
Core::App().passcodeLockValue(
|
Core::App().passcodeLockValue(
|
||||||
) | rpl::filter([=](bool locked) {
|
) | rpl::filter([=](bool locked) {
|
||||||
return locked && Core::App().maybeActiveSession();
|
return locked && Core::App().maybeActiveSession();
|
||||||
|
|
Loading…
Add table
Reference in a new issue