@@ -30,9 +30,9 @@ AudioPlayer::~AudioPlayer() {
3030 player_destroy (player_);
3131 player_ = nullptr ;
3232 }
33- if (timer_ ) {
34- ecore_timer_del (timer_ );
35- timer_ = nullptr ;
33+ if (timer_id_ != 0 ) {
34+ g_source_remove (timer_id_ );
35+ timer_id_ = 0 ;
3636 }
3737}
3838
@@ -346,8 +346,8 @@ void AudioPlayer::OnPrepared(void *data) {
346346 // On TV devices, callbacks are not executed on the main loop. Therefore
347347 // we explicitly transfer the callback to the main loop to avoid any race
348348 // conditions and to allow creating timer objects in StartPositionUpdates.
349- ecore_main_loop_thread_safe_call_async (
350- [](void * data) {
349+ g_idle_add (
350+ [](gpointer data) -> gboolean {
351351 auto *player = reinterpret_cast <AudioPlayer *>(data);
352352 player->preparing_ = false ;
353353
@@ -356,15 +356,15 @@ void AudioPlayer::OnPrepared(void *data) {
356356 player->prepared_listener_ (player->player_id_ , true );
357357 } catch (const AudioPlayerError &error) {
358358 player->log_listener_ (player->player_id_ , error.code ());
359- return ;
359+ return G_SOURCE_REMOVE ;
360360 }
361361 player_set_playback_rate (player->player_ , player->playback_rate_ );
362362
363363 if (player->should_play_ ) {
364364 int ret = player_start (player->player_ );
365365 if (ret != PLAYER_ERROR_NONE ) {
366366 player->log_listener_ (player->player_id_ , " player_start failed." );
367- return ;
367+ return G_SOURCE_REMOVE ;
368368 }
369369 player->StartPositionUpdates ();
370370 player->should_play_ = false ;
@@ -379,10 +379,11 @@ void AudioPlayer::OnPrepared(void *data) {
379379 player->seeking_ = false ;
380380 player->log_listener_ (player->player_id_ ,
381381 " player_set_play_position failed." );
382- return ;
382+ return G_SOURCE_REMOVE ;
383383 }
384384 player->should_seek_to_ = -1 ;
385385 }
386+ return G_SOURCE_REMOVE ;
386387 },
387388 data);
388389}
@@ -391,11 +392,12 @@ void AudioPlayer::OnSeekCompleted(void *data) {
391392 // On TV devices, callbacks are not executed on the main loop. Therefore
392393 // we explicitly transfer the callback to the main loop to avoid any race
393394 // conditions.
394- ecore_main_loop_thread_safe_call_async (
395- [](void * data) {
395+ g_idle_add (
396+ [](gpointer data) -> gboolean {
396397 auto *player = reinterpret_cast <AudioPlayer *>(data);
397398 player->seek_completed_listener_ (player->player_id_ );
398399 player->seeking_ = false ;
400+ return G_SOURCE_REMOVE ;
399401 },
400402 data);
401403}
@@ -404,8 +406,8 @@ void AudioPlayer::OnPlayCompleted(void *data) {
404406 // On TV devices, callbacks are not executed on the main loop. Therefore
405407 // we explicitly transfer the callback to the main loop to avoid any race
406408 // conditions.
407- ecore_main_loop_thread_safe_call_async (
408- [](void * data) {
409+ g_idle_add (
410+ [](gpointer data) -> gboolean {
409411 auto *player = reinterpret_cast <AudioPlayer *>(data);
410412 try {
411413 player->Seek (0 );
@@ -414,6 +416,7 @@ void AudioPlayer::OnPlayCompleted(void *data) {
414416 } catch (const AudioPlayerError &error) {
415417 player->log_listener_ (player->player_id_ , error.code ());
416418 }
419+ return G_SOURCE_REMOVE ;
417420 },
418421 data);
419422}
@@ -433,27 +436,27 @@ void AudioPlayer::OnError(int code, void *data) {
433436}
434437
435438void AudioPlayer::StartPositionUpdates () {
436- if (!timer_ ) {
439+ if (timer_id_ == 0 ) {
437440 // The audioplayers app facing package expects position
438441 // update events to fire roughly every 200 milliseconds.
439- const double kTimeInterval = 0.2 ;
440- timer_ = ecore_timer_add (kTimeInterval , OnPositionUpdate, this );
441- if (!timer_ ) {
442+ const guint kTimeInterval = 200 ;
443+ timer_id_ = g_timeout_add (kTimeInterval , OnPositionUpdate, this );
444+ if (timer_id_ == 0 ) {
442445 log_listener_ (player_id_, " Failed to add a position update timer." );
443446 }
444447 }
445448}
446449
447- Eina_Bool AudioPlayer::OnPositionUpdate (void * data) {
450+ gboolean AudioPlayer::OnPositionUpdate (gpointer data) {
448451 auto *player = reinterpret_cast <AudioPlayer *>(data);
449452 try {
450453 if (player->IsPlaying ()) {
451454 player->duration_listener_ (player->player_id_ , player->GetDuration ());
452- return ECORE_CALLBACK_RENEW ;
455+ return G_SOURCE_CONTINUE ;
453456 }
454457 } catch (const AudioPlayerError &error) {
455458 player->log_listener_ (player->player_id_ , " Failed to update position." );
456459 }
457- player->timer_ = nullptr ;
458- return ECORE_CALLBACK_CANCEL ;
460+ player->timer_id_ = 0 ;
461+ return G_SOURCE_REMOVE ;
459462}
0 commit comments