Added new event of seeking to media player.

This commit is contained in:
23rd 2021-06-07 08:31:27 +03:00
parent b553520a48
commit 8356bac6d7
2 changed files with 27 additions and 0 deletions

View file

@ -411,6 +411,16 @@ rpl::producer<> Media::Player::Instance::startsPlay(
}) | rpl::to_empty;
}
auto Media::Player::Instance::seekingChanges(AudioMsgId::Type type) const
-> rpl::producer<Media::Player::Instance::Seeking> {
return _seekingChanges.events(
) | rpl::filter([=](SeekingChanges data) {
return data.type == type;
}) | rpl::map([](SeekingChanges data) {
return data.seeking;
});
}
not_null<Instance*> instance() {
Expects(SingleInstance != nullptr);
return SingleInstance;
@ -625,6 +635,7 @@ void Instance::startSeeking(AudioMsgId::Type type) {
}
pause(type);
emitUpdate(type);
_seekingChanges.fire({ .seeking = Seeking::Start, .type = type });
}
void Instance::finishSeeking(AudioMsgId::Type type, float64 progress) {
@ -643,6 +654,7 @@ void Instance::finishSeeking(AudioMsgId::Type type, float64 progress) {
}
}
cancelSeeking(type);
_seekingChanges.fire({ .seeking = Seeking::Finish, .type = type });
}
void Instance::cancelSeeking(AudioMsgId::Type type) {
@ -650,6 +662,7 @@ void Instance::cancelSeeking(AudioMsgId::Type type) {
data->seeking = AudioMsgId();
}
emitUpdate(type);
_seekingChanges.fire({ .seeking = Seeking::Cancel, .type = type });
}
void Instance::updateVoicePlaybackSpeed() {

View file

@ -51,6 +51,12 @@ not_null<Instance*> instance();
class Instance : private base::Subscriber {
public:
enum class Seeking {
Start,
Finish,
Cancel,
};
void play(AudioMsgId::Type type);
void pause(AudioMsgId::Type type);
void stop(AudioMsgId::Type type);
@ -155,6 +161,8 @@ public:
rpl::producer<> stops(AudioMsgId::Type type) const;
rpl::producer<> startsPlay(AudioMsgId::Type type) const;
rpl::producer<Seeking> seekingChanges(AudioMsgId::Type type) const;
bool pauseGifByRoundVideo() const;
void documentLoadProgress(DocumentData *document);
@ -189,6 +197,11 @@ private:
std::unique_ptr<Streamed> streamed;
};
struct SeekingChanges {
Seeking seeking;
AudioMsgId::Type type;
};
Instance();
~Instance();
@ -269,6 +282,7 @@ private:
rpl::event_stream<AudioMsgId::Type> _playerStopped;
rpl::event_stream<AudioMsgId::Type> _playerStartedPlay;
rpl::event_stream<TrackState> _updatedNotifier;
rpl::event_stream<SeekingChanges> _seekingChanges;
rpl::lifetime _lifetime;
};