Skip to content

Commit c8a3403

Browse files
committed
Apply review suggestions
1 parent b412746 commit c8a3403

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

packages/audioplayers/tizen/src/audio_player.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void AudioPlayer::Release() {
109109
}
110110
}
111111

112-
void AudioPlayer::Seek(int position) {
112+
void AudioPlayer::Seek(int32_t position) {
113113
if (seeking_) {
114114
return;
115115
}
@@ -205,7 +205,7 @@ void AudioPlayer::SetReleaseMode(ReleaseMode mode) {
205205
}
206206

207207
int AudioPlayer::GetDuration() {
208-
int duration;
208+
int32_t duration;
209209
int ret = player_get_duration(player_, &duration);
210210
if (ret != PLAYER_ERROR_NONE) {
211211
throw AudioPlayerError("player_get_duration failed",
@@ -215,7 +215,7 @@ int AudioPlayer::GetDuration() {
215215
}
216216

217217
int AudioPlayer::GetCurrentPosition() {
218-
int position;
218+
int32_t position;
219219
int ret = player_get_play_position(player_, &position);
220220
if (ret != PLAYER_ERROR_NONE) {
221221
throw AudioPlayerError("player_get_play_position failed",
@@ -411,8 +411,8 @@ Eina_Bool AudioPlayer::OnPositionUpdate(void *data) {
411411
auto *player = reinterpret_cast<AudioPlayer *>(data);
412412
try {
413413
if (player->IsPlaying()) {
414-
int duration = player->GetDuration();
415-
int position = player->GetCurrentPosition();
414+
int32_t duration = player->GetDuration();
415+
int32_t position = player->GetCurrentPosition();
416416
player->update_position_listener_(player->player_id_, duration, position);
417417
return ECORE_CALLBACK_RENEW;
418418
}

packages/audioplayers/tizen/src/audio_player.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
enum class ReleaseMode { kRelease, kLoop, kStop };
1212

1313
using PreparedListener =
14-
std::function<void(const std::string &player_id, int duration)>;
15-
using UpdatePositionListener = std::function<void(
16-
const std::string &player_id, const int duration, const int position)>;
14+
std::function<void(const std::string &player_id, int32_t duration)>;
15+
using UpdatePositionListener =
16+
std::function<void(const std::string &player_id, const int32_t duration,
17+
const int32_t position)>;
1718
using SeekCompletedListener = std::function<void(const std::string &player_id)>;
1819
using PlayCompletedListener = std::function<void(const std::string &player_id)>;
1920
using ErrorListener = std::function<void(const std::string &player_id,
@@ -33,7 +34,7 @@ class AudioPlayer {
3334
void Pause();
3435
void Stop();
3536
void Release();
36-
void Seek(int position); // milliseconds
37+
void Seek(int32_t position); // milliseconds
3738

3839
// If you use HTTP or RTSP, URI must start with "http://" or "rtsp://".
3940
// The default protocol is "file://".
@@ -42,8 +43,8 @@ class AudioPlayer {
4243
void SetVolume(double volume);
4344
void SetPlaybackRate(double rate);
4445
void SetReleaseMode(ReleaseMode mode);
45-
int GetDuration();
46-
int GetCurrentPosition();
46+
int32_t GetDuration();
47+
int32_t GetCurrentPosition();
4748
std::string GetPlayerId() const { return player_id_; }
4849
bool IsPlaying();
4950

packages/audioplayers/tizen/src/audioplayers_tizen_plugin.cc

+29-19
Original file line numberDiff line numberDiff line change
@@ -96,36 +96,44 @@ class AudioplayersTizenPlugin : public flutter::Plugin {
9696
AudioPlayer *player = GetAudioPlayer(player_id, mode);
9797

9898
try {
99-
const auto &method_name = method_call.method_name();
99+
const std::string &method_name = method_call.method_name();
100100
if (method_name == "play") {
101101
double volume = 0.0;
102-
std::string url;
103-
int32_t position = 0;
104102
if (GetValueFromEncodableMap(arguments, "volume", volume)) {
105103
player->SetVolume(volume);
106104
}
105+
106+
std::string url;
107107
if (GetValueFromEncodableMap(arguments, "url", url)) {
108108
player->SetUrl(url);
109109
}
110+
110111
player->Play();
112+
113+
int32_t position = 0;
111114
if (GetValueFromEncodableMap(arguments, "position", position)) {
112115
player->Seek(position);
113116
}
117+
114118
result->Success(flutter::EncodableValue(1));
115119
} else if (method_name == "playBytes") {
116120
double volume = 0.0;
117-
std::vector<uint8_t> bytes;
118-
int32_t position = 0;
119121
if (GetValueFromEncodableMap(arguments, "volume", volume)) {
120122
player->SetVolume(volume);
121123
}
124+
125+
std::vector<uint8_t> bytes;
122126
if (GetValueFromEncodableMap(arguments, "bytes", bytes)) {
123127
player->SetDataSource(bytes);
124128
}
129+
125130
player->Play();
131+
132+
int32_t position = 0;
126133
if (GetValueFromEncodableMap(arguments, "position", position)) {
127134
player->Seek(position);
128135
}
136+
129137
result->Success(flutter::EncodableValue(1));
130138
} else if (method_name == "resume") {
131139
player->Play();
@@ -178,15 +186,16 @@ class AudioplayersTizenPlugin : public flutter::Plugin {
178186
return iter->second.get();
179187
}
180188

181-
PreparedListener prepared_listener =
182-
[channel = channel_.get()](const std::string &player_id, int duration) {
183-
flutter::EncodableMap wrapped = {{flutter::EncodableValue("playerId"),
184-
flutter::EncodableValue(player_id)},
185-
{flutter::EncodableValue("value"),
186-
flutter::EncodableValue(duration)}};
187-
auto arguments = std::make_unique<flutter::EncodableValue>(wrapped);
188-
channel->InvokeMethod("audio.onDuration", std::move(arguments));
189-
};
189+
PreparedListener prepared_listener = [channel = channel_.get()](
190+
const std::string &player_id,
191+
int32_t duration) {
192+
flutter::EncodableMap wrapped = {{flutter::EncodableValue("playerId"),
193+
flutter::EncodableValue(player_id)},
194+
{flutter::EncodableValue("value"),
195+
flutter::EncodableValue(duration)}};
196+
auto arguments = std::make_unique<flutter::EncodableValue>(wrapped);
197+
channel->InvokeMethod("audio.onDuration", std::move(arguments));
198+
};
190199

191200
SeekCompletedListener seek_completed_listener =
192201
[channel = channel_.get()](const std::string &player_id) {
@@ -200,24 +209,25 @@ class AudioplayersTizenPlugin : public flutter::Plugin {
200209

201210
UpdatePositionListener update_position_listener =
202211
[channel = channel_.get()](const std::string &player_id,
203-
const int duration, const int position) {
204-
flutter::EncodableMap durationWrapped = {
212+
const int32_t duration,
213+
const int32_t position) {
214+
flutter::EncodableMap duration_wrapped = {
205215
{flutter::EncodableValue("playerId"),
206216
flutter::EncodableValue(player_id)},
207217
{flutter::EncodableValue("value"),
208218
flutter::EncodableValue(duration)}};
209219
channel->InvokeMethod(
210220
"audio.onDuration",
211-
std::make_unique<flutter::EncodableValue>(durationWrapped));
221+
std::make_unique<flutter::EncodableValue>(duration_wrapped));
212222

213-
flutter::EncodableMap positionWrapped = {
223+
flutter::EncodableMap position_wrapped = {
214224
{flutter::EncodableValue("playerId"),
215225
flutter::EncodableValue(player_id)},
216226
{flutter::EncodableValue("value"),
217227
flutter::EncodableValue(position)}};
218228
channel->InvokeMethod(
219229
"audio.onCurrentPosition",
220-
std::make_unique<flutter::EncodableValue>(positionWrapped));
230+
std::make_unique<flutter::EncodableValue>(position_wrapped));
221231
};
222232

223233
PlayCompletedListener play_completed_listener =

0 commit comments

Comments
 (0)