Skip to content

Commit 4fb64af

Browse files
committed
[audioplayers] Remove Ecore API
Replace the Ecore main-loop and timer APIs with their GLib APIs.
1 parent c062f30 commit 4fb64af

5 files changed

Lines changed: 32 additions & 25 deletions

File tree

packages/audioplayers/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.1.4
2+
3+
* Remove Ecore API.
4+
15
## 3.1.3
26

37
* Adds compatibility with `http` 1.0 in example.

packages/audioplayers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This package is not an _endorsed_ implementation of `audioplayers`. Therefore, y
1111
```yaml
1212
dependencies:
1313
audioplayers: ^6.6.0
14-
audioplayers_tizen: ^3.1.3
14+
audioplayers_tizen: ^3.1.4
1515

1616
```
1717

packages/audioplayers/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: audioplayers_tizen
22
description: Tizen implementation of the audioplayers plugin.
33
homepage: https://github.com/flutter-tizen/plugins
44
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/audioplayers
5-
version: 3.1.3
5+
version: 3.1.4
66

77
environment:
88
sdk: ^3.6.0

packages/audioplayers/tizen/src/audio_player.cc

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

435438
void 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
}

packages/audioplayers/tizen/src/audio_player.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef FLUTTER_PLUGIN_AUDIO_PLAYER_H_
66
#define FLUTTER_PLUGIN_AUDIO_PLAYER_H_
77

8-
#include <Ecore.h>
8+
#include <glib.h>
99
#include <player.h>
1010

1111
#include <functional>
@@ -71,7 +71,7 @@ class AudioPlayer {
7171
static void OnPlayCompleted(void *data);
7272
static void OnInterrupted(player_interrupted_code_e code, void *data);
7373
static void OnError(int code, void *data);
74-
static Eina_Bool OnPositionUpdate(void *data);
74+
static gboolean OnPositionUpdate(gpointer data);
7575

7676
player_h player_ = nullptr;
7777
const std::string player_id_;
@@ -84,7 +84,7 @@ class AudioPlayer {
8484
bool preparing_ = false;
8585
bool seeking_ = false;
8686
bool should_play_ = false;
87-
Ecore_Timer *timer_ = nullptr;
87+
guint timer_id_ = 0;
8888

8989
PreparedListener prepared_listener_;
9090
DurationListener duration_listener_;

0 commit comments

Comments
 (0)