Skip to content

Commit

Permalink
fix(windows): send onDuration event when play/resume (#1245)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 authored Aug 15, 2022
1 parent e1b1584 commit 8108ff4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
25 changes: 13 additions & 12 deletions packages/audioplayers_windows/windows/audio_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,34 +108,33 @@ void AudioPlayer::OnTimeUpdate() {
}
}

void AudioPlayer::OnSeekCompleted() {
void AudioPlayer::OnDurationUpdate() {
if(this->_channel) {
this->_channel->InvokeMethod("audio.onSeekComplete",
this->_channel->InvokeMethod("audio.onDuration",
std::make_unique<flutter::EncodableValue>(
flutter::EncodableMap({
{flutter::EncodableValue("playerId"), flutter::EncodableValue(_playerId)},
{flutter::EncodableValue("value"), flutter::EncodableValue(true)}
{flutter::EncodableValue("value"), flutter::EncodableValue((int64_t)m_mediaEngineWrapper->GetDuration() / 10000)}
})));
}
}

void AudioPlayer::SendInitialized() {
void AudioPlayer::OnSeekCompleted() {
if(this->_channel) {
this->_channel->InvokeMethod("audio.onDuration",
std::make_unique<flutter::EncodableValue>(
flutter::EncodableMap({
{flutter::EncodableValue("playerId"), flutter::EncodableValue(_playerId)},
{flutter::EncodableValue("value"), flutter::EncodableValue((int64_t)m_mediaEngineWrapper->GetDuration() / 10000)}
})));
this->_channel->InvokeMethod("audio.onCurrentPosition",
this->_channel->InvokeMethod("audio.onSeekComplete",
std::make_unique<flutter::EncodableValue>(
flutter::EncodableMap({
{flutter::EncodableValue("playerId"), flutter::EncodableValue(_playerId)},
{flutter::EncodableValue("value"), flutter::EncodableValue((int64_t)m_mediaEngineWrapper->GetMediaTime() / 10000)}
{flutter::EncodableValue("value"), flutter::EncodableValue(true)}
})));
}
}

void AudioPlayer::SendInitialized() {
OnDurationUpdate();
OnTimeUpdate();
}

void AudioPlayer::Dispose() {
if (_isInitialized) {
m_mediaEngineWrapper->Pause();
Expand Down Expand Up @@ -167,6 +166,7 @@ void AudioPlayer::SetPlaybackSpeed(double playbackSpeed) {

void AudioPlayer::Play() {
m_mediaEngineWrapper->StartPlayingFrom(m_mediaEngineWrapper->GetMediaTime());
OnDurationUpdate();
}

void AudioPlayer::Pause() {
Expand All @@ -175,6 +175,7 @@ void AudioPlayer::Pause() {

void AudioPlayer::Resume() {
m_mediaEngineWrapper->Resume();
OnDurationUpdate();
}

int64_t AudioPlayer::GetPosition() {
Expand Down
3 changes: 2 additions & 1 deletion packages/audioplayers_windows/windows/audio_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ class AudioPlayer {
void OnMediaError(MF_MEDIA_ENGINE_ERR error, HRESULT hr);
void OnMediaStateChange(media::MediaEngineWrapper::BufferingState bufferingState);
void OnPlaybackEnded();
void OnDurationUpdate();
void OnTimeUpdate();
void OnSeekCompleted();

std::string _playerId;

flutter::MethodChannel<flutter::EncodableValue>* _channel;

};
};

0 comments on commit 8108ff4

Please sign in to comment.