Skip to content

Commit 46a2887

Browse files
authored
[audioplayers] Fix integration_test issue and update to 6.4.0 (#841)
1 parent 79cde23 commit 46a2887

File tree

8 files changed

+133
-30
lines changed

8 files changed

+133
-30
lines changed

packages/audioplayers/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 3.1.1
2+
3+
* Update audioplayers to 6.4.0.
4+
* Update audioplayers_platform_interface to 7.1.0.
5+
* Add 'xyz.luan/audioplayers.global' Method Channel.
6+
* Add 'xyz.luan/audioplayers.global/events' Event Channel.
7+
* Update example app
8+
19
## 3.1.0
210

311
* Update audioplayers to 6.1.0.

packages/audioplayers/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ This package is not an _endorsed_ implementation of `audioplayers`. Therefore, y
1010

1111
```yaml
1212
dependencies:
13-
audioplayers: ^5.1.0
14-
audioplayers_tizen: ^3.0.2
13+
audioplayers: ^6.4.0
14+
audioplayers_tizen: ^3.1.1
1515

1616
```
1717

packages/audioplayers/example/lib/tabs/audio_context.dart

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:audioplayers_tizen_example/components/drop_down.dart';
44
import 'package:audioplayers_tizen_example/components/tab_content.dart';
55
import 'package:audioplayers_tizen_example/components/tabs.dart';
66
import 'package:audioplayers_tizen_example/utils.dart';
7+
import 'package:flutter/foundation.dart';
78
import 'package:flutter/material.dart';
89

910
class AudioContextTab extends StatefulWidget {
@@ -27,6 +28,9 @@ class AudioContextTabState extends State<AudioContextTab>
2728
/// Set config for each platform individually
2829
AudioContext audioContext = AudioContext();
2930

31+
bool isLocal = true;
32+
bool isGlobal = false;
33+
3034
@override
3135
Widget build(BuildContext context) {
3236
super.build(context);
@@ -36,21 +40,31 @@ class AudioContextTabState extends State<AudioContextTab>
3640
Row(
3741
mainAxisAlignment: MainAxisAlignment.spaceAround,
3842
children: [
43+
ToggleButtons(
44+
isSelected: [isGlobal, isLocal],
45+
onPressed: (index) {
46+
if (index == 0) {
47+
setState(() {
48+
isGlobal = !isGlobal;
49+
});
50+
} else if (index == 1) {
51+
setState(() {
52+
isLocal = !isLocal;
53+
});
54+
}
55+
},
56+
borderRadius: const BorderRadius.all(Radius.circular(8)),
57+
selectedBorderColor: Theme.of(context).primaryColor,
58+
children: const [
59+
Padding(padding: EdgeInsets.all(8), child: Text('Global')),
60+
Padding(padding: EdgeInsets.all(8), child: Text('Local')),
61+
],
62+
),
3963
ElevatedButton.icon(
4064
icon: const Icon(Icons.undo),
4165
label: const Text('Reset'),
4266
onPressed: () => updateConfig(AudioContextConfig()),
4367
),
44-
ElevatedButton.icon(
45-
icon: const Icon(Icons.public),
46-
label: const Text('Global'),
47-
onPressed: () => _global.setAudioContext(audioContext),
48-
),
49-
ElevatedButton.icon(
50-
icon: const Icon(Icons.looks_one),
51-
label: const Text('Local'),
52-
onPressed: () => player.setAudioContext(audioContext),
53-
),
5468
],
5569
),
5670
const SizedBox(height: 8),
@@ -62,12 +76,18 @@ class AudioContextTabState extends State<AudioContextTab>
6276
label: 'Generic Flags',
6377
content: _genericTab(),
6478
),
65-
TabData(
66-
key: 'contextTab-android',
67-
label: 'Android',
68-
content: _androidTab(),
69-
),
70-
TabData(key: 'contextTab-ios', label: 'iOS', content: _iosTab()),
79+
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android)
80+
TabData(
81+
key: 'contextTab-android',
82+
label: 'Android',
83+
content: _androidTab(),
84+
),
85+
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.iOS)
86+
TabData(
87+
key: 'contextTab-ios',
88+
label: 'iOS',
89+
content: _iosTab(),
90+
),
7191
],
7292
),
7393
),
@@ -81,6 +101,7 @@ class AudioContextTabState extends State<AudioContextTab>
81101
setState(() {
82102
audioContextConfig = newConfig;
83103
audioContext = context;
104+
_applyAudioContext(audioContext);
84105
});
85106
} on AssertionError catch (e) {
86107
toast(e.message.toString());
@@ -90,6 +111,7 @@ class AudioContextTabState extends State<AudioContextTab>
90111
void updateAudioContextAndroid(AudioContextAndroid contextAndroid) {
91112
setState(() {
92113
audioContext = audioContext.copy(android: contextAndroid);
114+
_applyAudioContext(audioContext);
93115
});
94116
}
95117

@@ -98,12 +120,22 @@ class AudioContextTabState extends State<AudioContextTab>
98120
final context = buildContextIOS();
99121
setState(() {
100122
audioContext = audioContext.copy(iOS: context);
123+
_applyAudioContext(audioContext);
101124
});
102125
} on AssertionError catch (e) {
103126
toast(e.message.toString());
104127
}
105128
}
106129

130+
void _applyAudioContext(AudioContext context) {
131+
if (isGlobal) {
132+
_global.setAudioContext(context);
133+
}
134+
if (isLocal) {
135+
player.setAudioContext(context);
136+
}
137+
}
138+
107139
Widget _genericTab() {
108140
return TabContent(
109141
children: [

packages/audioplayers/example/lib/tabs/sources.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final mp3Url2 = '$host/files/audio/nasa_on_a_mission.mp3';
2424
final m3u8StreamUrl =
2525
useLocalServer
2626
? '$host/files/live_streams/nasa_power_of_the_rovers.m3u8'
27-
: 'https://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/nonuk/sbr_low/ak/bbc_world_service.m3u8';
27+
: 'https://ll-hls-test.cdn-apple.com/llhls4/ll-hls-test-04/multi.m3u8';
2828
final mpgaStreamUrl =
2929
useLocalServer
3030
? '$host/stream/mpeg'
@@ -141,7 +141,7 @@ class _SourcesTabState extends State<SourcesTab>
141141
_createSourceTile(
142142
setSourceKey: const Key('setSource-url-remote-m3u8'),
143143
title: 'Remote URL M3U8',
144-
subtitle: 'BBC stream',
144+
subtitle: 'HLS Low-Latency Live Stream',
145145
source: UrlSource(m3u8StreamUrl),
146146
),
147147
_createSourceTile(

packages/audioplayers/example/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ environment:
77
flutter: ">=3.13.0"
88

99
dependencies:
10-
audioplayers: ^6.1.0
10+
audioplayers: ^6.4.0
1111
audioplayers_tizen:
1212
path: ../
1313
collection: ^1.16.0
14-
file_picker: ^5.0.1
14+
file_picker: ^8.0.3
1515
flutter:
1616
sdk: flutter
17-
http: ">=0.13.1 <2.0.0"
17+
http: ^1.0.0
1818
path_provider: ^2.0.12
1919
path_provider_tizen:
2020
path: ../../path_provider/
2121
provider: ^6.0.5
2222

2323
dev_dependencies:
24-
flame_lint: ^0.1.0
24+
flame_lint: ^1.0.0
2525
flutter_driver:
2626
sdk: flutter
2727
flutter_test:

packages/audioplayers/pubspec.yaml

Lines changed: 2 additions & 2 deletions
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.0.2
5+
version: 3.1.1
66

77
environment:
88
sdk: ">=3.1.0 <4.0.0"
@@ -16,7 +16,7 @@ flutter:
1616
fileName: audioplayers_tizen_plugin.h
1717

1818
dependencies:
19-
audioplayers_platform_interface: ^7.0.0
19+
audioplayers_platform_interface: ^7.1.0
2020
flutter:
2121
sdk: flutter
2222

packages/audioplayers/tizen/src/audio_player.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ int AudioPlayer::GetCurrentPosition() {
224224
// TODO(jsuya) : When stop() or pause() is called in AudioPlayer 6.1.0,
225225
// PositionUpdater's stopAndUpdate() is called. At this time, getPosition() is
226226
// called, but in ReleaseMode, the player is released after Stop(), so an
227-
// eception is thrown. Since there are differences from the implementation in
227+
// exception is thrown. Since there are differences from the implementation in
228228
// the frontend package, an exception is not thrown in this case.
229229
if (!player_ && released_ && release_mode_ == ReleaseMode::kRelease) {
230230
LOG_ERROR("The player has already been released.");

packages/audioplayers/tizen/src/audioplayers_tizen_plugin.cc

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,31 @@ class AudioplayersTizenPlugin : public flutter::Plugin {
105105
registrar->messenger(), "xyz.luan/audioplayers",
106106
&flutter::StandardMethodCodec::GetInstance());
107107

108+
auto global_method_channel = std::make_unique<FlMethodChannel>(
109+
registrar->messenger(), "xyz.luan/audioplayers.global",
110+
&flutter::StandardMethodCodec::GetInstance());
111+
112+
auto global_event_channel = std::make_unique<FlEventChannel>(
113+
registrar->messenger(), "xyz.luan/audioplayers.global/events",
114+
&flutter::StandardMethodCodec::GetInstance());
115+
108116
auto plugin = std::make_unique<AudioplayersTizenPlugin>(registrar);
109117

110118
channel->SetMethodCallHandler(
111119
[plugin_pointer = plugin.get()](const auto &call, auto result) {
112120
plugin_pointer->HandleMethodCall(call, std::move(result));
113121
});
114-
plugin->channel_ = std::move(channel);
122+
global_method_channel->SetMethodCallHandler(
123+
[plugin_pointer = plugin.get()](const auto &call, auto result) {
124+
plugin_pointer->HandleGlobalMethodCall(call, std::move(result));
125+
});
126+
127+
global_event_channel->SetStreamHandler(
128+
std::make_unique<AudioPlayerStreamHandler>(
129+
[plugin_pointer =
130+
plugin.get()](std::unique_ptr<FlEventSink> event_sink) {
131+
plugin_pointer->global_event_sinks_ = std::move(event_sink);
132+
}));
115133

116134
registrar->AddPlugin(std::move(plugin));
117135
}
@@ -222,6 +240,52 @@ class AudioplayersTizenPlugin : public flutter::Plugin {
222240
}
223241
}
224242

243+
void HandleGlobalMethodCall(const FlMethodCall &method_call,
244+
std::unique_ptr<FlMethodResult> result) {
245+
const auto *arguments =
246+
std::get_if<flutter::EncodableMap>(method_call.arguments());
247+
try {
248+
const std::string &method_name = method_call.method_name();
249+
if (method_name == "init") {
250+
for (auto &pair : audio_players_) {
251+
DisposeAudioPlayer(pair.first);
252+
}
253+
audio_players_.clear();
254+
} else if (method_name == "setAudioContext") {
255+
const std::string message =
256+
"Setting AudioContext is not supported on Tizen";
257+
flutter::EncodableMap map = {{flutter::EncodableValue("event"),
258+
flutter::EncodableValue("audio.onLog")},
259+
{flutter::EncodableValue("value"),
260+
flutter::EncodableValue(message)}};
261+
global_event_sinks_->Success(flutter::EncodableValue(map));
262+
} else if (method_name == "emitLog") {
263+
if (arguments) {
264+
auto message = GetRequiredArg<std::string>(arguments, "message");
265+
flutter::EncodableMap map = {{flutter::EncodableValue("event"),
266+
flutter::EncodableValue("audio.onLog")},
267+
{flutter::EncodableValue("value"),
268+
flutter::EncodableValue(message)}};
269+
global_event_sinks_->Success(flutter::EncodableValue(map));
270+
}
271+
} else if (method_name == "emitError") {
272+
if (arguments) {
273+
auto code = GetRequiredArg<std::string>(arguments, "code");
274+
auto message = GetRequiredArg<std::string>(arguments, "message");
275+
global_event_sinks_->Error(code, message, flutter::EncodableValue());
276+
}
277+
} else {
278+
result->NotImplemented();
279+
return;
280+
}
281+
result->Success();
282+
} catch (const std::invalid_argument &error) {
283+
result->Error(kInvalidArgument, error.what());
284+
} catch (const AudioPlayerError &error) {
285+
result->Error(error.code(), error.message());
286+
}
287+
}
288+
225289
AudioPlayer *GetAudioPlayer(const std::string &player_id) {
226290
auto iter = audio_players_.find(player_id);
227291
if (iter != audio_players_.end()) {
@@ -295,10 +359,9 @@ class AudioplayersTizenPlugin : public flutter::Plugin {
295359
event_sinks_.erase(player_id);
296360
}
297361

298-
std::unique_ptr<FlMethodChannel> channel_;
299-
300362
std::map<std::string, std::unique_ptr<AudioPlayer>> audio_players_;
301363
std::map<std::string, std::unique_ptr<FlEventSink>> event_sinks_;
364+
std::unique_ptr<FlEventSink> global_event_sinks_;
302365

303366
flutter::PluginRegistrar *registrar_;
304367
};

0 commit comments

Comments
 (0)