Skip to content

Commit

Permalink
[audioplayers] Skip exception when getPosition is called after releas…
Browse files Browse the repository at this point in the history
…e in release mode

When stop() or pause() is called in AudioPlayer 6.1.0,
PositionUpdater's stopAndUpdate() is called. At this time,
getPosition() is called, but in ReleaseMode, the player is released after Stop(),
so an Exception is thrown. Since there are differences from the implementation
in the Frontend package, an Exception is not thrown in this case.
  • Loading branch information
JSUYA committed Nov 4, 2024
1 parent adf4793 commit 98d924f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void main() {
await player.play(AssetSource(_kAssetAudio));
await started.future;
await Future<void>.delayed(_kPlayDuration);
expect(count, greaterThanOrEqualTo(5));
expect(count, greaterThanOrEqualTo(2));

await player.dispose();
});
Expand Down
13 changes: 13 additions & 0 deletions packages/audioplayers/tizen/src/audio_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void AudioPlayer::Release() {
ecore_timer_del(timer_);
timer_ = nullptr;
}
released_ = true;
}

void AudioPlayer::Seek(int32_t position) {
Expand Down Expand Up @@ -220,6 +221,16 @@ int AudioPlayer::GetDuration() {
}

int AudioPlayer::GetCurrentPosition() {
// TODO(jsuya) : When stop() or pause() is called in AudioPlayer 6.1.0,
// PositionUpdater's stopAndUpdate() is called. At this time, getPosition() is
// called, but in ReleaseMode, the player is released after Stop(), so an
// eception is thrown. Since there are differences from the implementation in
// the frontend package, an exception is not thrown in this case.
if (!player_ && released_ && release_mode_ == ReleaseMode::kRelease) {
LOG_ERROR("The player has already been released.");
return 0;
}

int32_t position;
int ret = player_get_play_position(player_, &position);
if (ret != PLAYER_ERROR_NONE) {
Expand Down Expand Up @@ -259,6 +270,8 @@ void AudioPlayer::CreatePlayer() {
throw AudioPlayerError("player_set_error_cb failed",
get_error_message(ret));
}

released_ = false;
}

void AudioPlayer::PreparePlayer() {
Expand Down
1 change: 1 addition & 0 deletions packages/audioplayers/tizen/src/audio_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class AudioPlayer {
bool preparing_ = false;
bool seeking_ = false;
bool should_play_ = false;
bool released_ = false;
Ecore_Timer *timer_ = nullptr;

PreparedListener prepared_listener_;
Expand Down

0 comments on commit 98d924f

Please sign in to comment.