Skip to content

Commit

Permalink
fix: missing onDuration event, free previous source when set url on L…
Browse files Browse the repository at this point in the history
…inux (#1129)
  • Loading branch information
Gustl22 committed May 21, 2022
1 parent 8db4dca commit b523a39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/audioplayers_linux/linux/audio_player.cc
Expand Up @@ -40,9 +40,8 @@ void AudioPlayer::SourceSetup(GstElement *playbin, GstElement *source,
void AudioPlayer::SetSourceUrl(std::string url) {
if (_url != url) {
_url = url;
if (_url.empty()) {
gst_element_set_state(playbin, GST_STATE_NULL);
} else {
gst_element_set_state(playbin, GST_STATE_NULL);
if (!_url.empty()) {
g_object_set(playbin, "uri", _url.c_str(), NULL);
if (playbin->current_state != GST_STATE_READY) {
gst_element_set_state(playbin, GST_STATE_READY);
Expand Down Expand Up @@ -128,6 +127,7 @@ void AudioPlayer::OnMediaStateChange(GstObject *src, GstState *old_state,
if (*new_state >= GST_STATE_READY) {
if (!this->_isInitialized) {
this->_isInitialized = true;
Pause(); // Need to set to pause state, in order to get duration
}
} else if (this->_isInitialized) {
this->_isInitialized = false;
Expand Down Expand Up @@ -256,7 +256,7 @@ void AudioPlayer::SetPlayback(int64_t position, double rate) {
}

void AudioPlayer::SetPlaybackRate(double rate) {
SetPlayback(GetPosition(), _playbackRate);
SetPlayback(GetPosition(), rate);
}

/**
Expand Down Expand Up @@ -308,6 +308,7 @@ void AudioPlayer::Pause() {
std::string("Unable to set the pipeline to the paused state."));
return;
}
OnPositionUpdate(); // Update to exact position when pausing
}

void AudioPlayer::Resume() {
Expand All @@ -321,6 +322,7 @@ void AudioPlayer::Resume() {
std::string("Unable to set the pipeline to the playing state."));
return;
}
OnDurationUpdate(); // Update duration when start playing, as no event is emitted elsewhere
}

void AudioPlayer::Dispose() {
Expand Down
2 changes: 1 addition & 1 deletion packages/audioplayers_linux/pubspec.yaml
Expand Up @@ -11,7 +11,7 @@ flutter:
pluginClass: AudioplayersLinuxPlugin

dependencies:
audioplayers_platform_interface: ^1.0.0-rc.1
audioplayers_platform_interface: ^1.0.0-rc.2
flutter:
sdk: flutter

Expand Down

0 comments on commit b523a39

Please sign in to comment.