@@ -84,8 +84,7 @@ void AudioPlayer::Play() {
84
84
}
85
85
86
86
void AudioPlayer::Pause () {
87
- player_state_e state = GetPlayerState ();
88
- if (state == PLAYER_STATE_PLAYING) {
87
+ if (GetPlayerState () == PLAYER_STATE_PLAYING) {
89
88
int ret = player_pause (player_);
90
89
if (ret != PLAYER_ERROR_NONE) {
91
90
throw AudioPlayerError (" player_pause failed" , get_error_message (ret));
@@ -183,8 +182,7 @@ void AudioPlayer::SetVolume(double volume) {
183
182
}
184
183
volume_ = volume;
185
184
186
- player_state_e state = GetPlayerState ();
187
- if (state != PLAYER_STATE_NONE) {
185
+ if (GetPlayerState () != PLAYER_STATE_NONE) {
188
186
int ret = player_set_volume (player_, volume_, volume_);
189
187
if (ret != PLAYER_ERROR_NONE) {
190
188
throw AudioPlayerError (" player_set_volume failed" ,
@@ -217,8 +215,7 @@ void AudioPlayer::SetReleaseMode(ReleaseMode mode) {
217
215
if (release_mode_ != mode) {
218
216
release_mode_ = mode;
219
217
220
- player_state_e state = GetPlayerState ();
221
- if (state != PLAYER_STATE_NONE) {
218
+ if (GetPlayerState () != PLAYER_STATE_NONE) {
222
219
int ret =
223
220
player_set_looping (player_, (release_mode_ == ReleaseMode::kLoop ));
224
221
if (ret != PLAYER_ERROR_NONE) {
@@ -239,26 +236,21 @@ void AudioPlayer::SetLatencyMode(bool low_latency) {
239
236
}
240
237
241
238
int AudioPlayer::GetDuration () {
242
- // TODO(seungsoo47): Get duration in milliseconds, returns -1 if no duration
243
- // is available. The frontend package will handle these.
244
239
int32_t duration;
245
240
int ret = player_get_duration (player_, &duration);
246
241
if (ret != PLAYER_ERROR_NONE) {
247
- OnLog (" player_get_duration failed, " + std::string ( get_error_message (ret)));
248
- return - 1 ;
242
+ throw AudioPlayerError (" player_get_duration failed" ,
243
+ get_error_message (ret)) ;
249
244
}
250
245
return duration;
251
246
}
252
247
253
248
int AudioPlayer::GetCurrentPosition () {
254
- // TODO(seungsoo47): Get position in milliseconds, returns -1 if no position
255
- // is available. The frontend package will handle these.
256
249
int32_t position;
257
250
int ret = player_get_play_position (player_, &position);
258
251
if (ret != PLAYER_ERROR_NONE) {
259
- OnLog (" player_get_play_position failed, " +
260
- std::string (get_error_message (ret)));
261
- return -1 ;
252
+ throw AudioPlayerError (" player_get_play_position failed" ,
253
+ get_error_message (ret));
262
254
}
263
255
return position;
264
256
}
@@ -365,12 +357,13 @@ void AudioPlayer::OnPrepared(void *data) {
365
357
auto *player = reinterpret_cast <AudioPlayer *>(data);
366
358
player->preparing_ = false ;
367
359
368
- int32_t duration = player->GetDuration ();
369
- if (duration < 0 ) {
360
+ try {
361
+ player->duration_listener_ (player->player_id_ , player->GetDuration ());
362
+ player->prepared_listener_ (player->player_id_ , true );
363
+ } catch (AudioPlayerError &error) {
364
+ player->log_listener_ (player->player_id_ , error.code ());
370
365
return ;
371
366
}
372
- player->duration_listener_ (player->player_id_ , duration);
373
- player->prepared_listener_ (player->player_id_ , true );
374
367
375
368
player_set_playback_rate (player->player_ , player->playback_rate_ );
376
369
@@ -460,17 +453,14 @@ void AudioPlayer::StartPositionUpdates() {
460
453
461
454
Eina_Bool AudioPlayer::OnPositionUpdate (void *data) {
462
455
auto *player = reinterpret_cast <AudioPlayer *>(data);
463
- if (!player->IsPlaying ()) {
464
- player->timer_ = nullptr ;
465
- return ECORE_CALLBACK_CANCEL;
466
- }
467
-
468
- int32_t duration = player->GetDuration ();
469
- if (duration < 0 ) {
470
- player->timer_ = nullptr ;
471
- return ECORE_CALLBACK_CANCEL;
456
+ try {
457
+ if (player->IsPlaying ()) {
458
+ player->duration_listener_ (player->player_id_ , player->GetDuration ());
459
+ return ECORE_CALLBACK_RENEW;
460
+ }
461
+ } catch (const AudioPlayerError &error) {
462
+ player->log_listener_ (player->player_id_ , " Failed to update position." );
472
463
}
473
-
474
- player->duration_listener_ (player->player_id_ , duration);
475
- return ECORE_CALLBACK_RENEW;
464
+ player->timer_ = nullptr ;
465
+ return ECORE_CALLBACK_CANCEL;
476
466
}
0 commit comments