Skip to content

Commit 6f1d108

Browse files
authored
[audioplayers] Update audioplayers to 6.1.0 (#763)
1 parent f0b4723 commit 6f1d108

File tree

16 files changed

+360
-125
lines changed

16 files changed

+360
-125
lines changed

packages/audioplayers/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 3.1.0
2+
3+
* Update audioplayers to 6.1.0.
4+
* Update audioplayers_platform_interface to 7.0.0.
5+
* Changed to create a player when AudioPlayer created.
6+
* Remove 'audio.onCurrentPosition' method event.
7+
18
## 3.0.2
29

310
* Update minimum Flutter and Dart version to 3.13 and 3.1.
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
11
include: package:flame_lint/analysis_options.yaml
2-
3-
# The 'invariant_booleans' is a deprecated lint rule.
4-
# Remove the following lines when flame_lint package removes the rule
5-
# from its `analysis_options.yaml`.
6-
linter:
7-
rules:
8-
- invariant_booleans: false
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include: package:flame_lint/analysis_options.yaml
2+
3+
linter:
4+
rules:
5+
do_not_use_environment: false

packages/audioplayers/example/integration_test/audioplayers_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void main() {
176176
await player.play(AssetSource(_kAssetAudio));
177177
await started.future;
178178
await Future<void>.delayed(_kPlayDuration);
179-
expect(count, greaterThanOrEqualTo(5));
179+
expect(count, greaterThanOrEqualTo(2));
180180

181181
await player.dispose();
182182
});

packages/audioplayers/example/lib/components/dlg.dart

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,10 @@ class Dlg extends StatelessWidget {
3939
@override
4040
Widget build(BuildContext context) {
4141
return Dialog(
42-
shape: RoundedRectangleBorder(
43-
borderRadius: BorderRadius.circular(8.0),
44-
),
45-
elevation: 0,
46-
backgroundColor: Colors.white,
47-
child: Container(
42+
child: Padding(
4843
padding: const EdgeInsets.all(16.0),
49-
child: contentBox(context),
44+
child: child,
5045
),
5146
);
5247
}
53-
54-
Widget contentBox(BuildContext context) {
55-
return child;
56-
}
5748
}

packages/audioplayers/example/lib/components/player_widget.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:async';
33
import 'package:audioplayers/audioplayers.dart';
44
import 'package:flutter/material.dart';
55

6+
// This code is also used in the example.md. Please keep it up to date.
67
class PlayerWidget extends StatefulWidget {
78
final AudioPlayer player;
89

@@ -106,12 +107,12 @@ class _PlayerWidgetState extends State<PlayerWidget> {
106107
],
107108
),
108109
Slider(
109-
onChanged: (v) {
110+
onChanged: (value) {
110111
final duration = _duration;
111112
if (duration == null) {
112113
return;
113114
}
114-
final position = v * duration.inMilliseconds;
115+
final position = value * duration.inMilliseconds;
115116
player.seek(Duration(milliseconds: position.round()));
116117
},
117118
value: (_position != null &&
@@ -129,7 +130,6 @@ class _PlayerWidgetState extends State<PlayerWidget> {
129130
: '',
130131
style: const TextStyle(fontSize: 16.0),
131132
),
132-
Text('State: ${_playerState ?? '-'}'),
133133
],
134134
);
135135
}
@@ -159,10 +159,6 @@ class _PlayerWidgetState extends State<PlayerWidget> {
159159
}
160160

161161
Future<void> _play() async {
162-
final position = _position;
163-
if (position != null && position.inMilliseconds > 0) {
164-
await player.seek(position);
165-
}
166162
await player.resume();
167163
setState(() => _playerState = PlayerState.playing);
168164
}

packages/audioplayers/example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const defaultPlayerCount = 4;
1515

1616
typedef OnError = void Function(Exception exception);
1717

18+
/// The app is deployed at: https://bluefireteam.github.io/audioplayers/
1819
void main() {
1920
runApp(const MaterialApp(home: _ExampleApp()));
2021
}

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

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:audioplayers_tizen_example/components/cbx.dart';
33
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';
6+
import 'package:audioplayers_tizen_example/utils.dart';
67
import 'package:flutter/material.dart';
78

89
class AudioContextTab extends StatefulWidget {
@@ -27,7 +28,7 @@ class AudioContextTabState extends State<AudioContextTab>
2728
AudioContextConfig audioContextConfig = AudioContextConfig();
2829

2930
/// Set config for each platform individually
30-
AudioContext audioContext = const AudioContext();
31+
AudioContext audioContext = AudioContext();
3132

3233
@override
3334
Widget build(BuildContext context) {
@@ -82,10 +83,15 @@ class AudioContextTabState extends State<AudioContextTab>
8283
}
8384

8485
void updateConfig(AudioContextConfig newConfig) {
85-
setState(() {
86-
audioContextConfig = newConfig;
87-
audioContext = audioContextConfig.build();
88-
});
86+
try {
87+
final context = newConfig.build();
88+
setState(() {
89+
audioContextConfig = newConfig;
90+
audioContext = context;
91+
});
92+
} on AssertionError catch (e) {
93+
toast(e.message.toString());
94+
}
8995
}
9096

9197
void updateAudioContextAndroid(AudioContextAndroid contextAndroid) {
@@ -94,10 +100,15 @@ class AudioContextTabState extends State<AudioContextTab>
94100
});
95101
}
96102

97-
void updateAudioContextIOS(AudioContextIOS contextIOS) {
98-
setState(() {
99-
audioContext = audioContext.copy(iOS: contextIOS);
100-
});
103+
void updateAudioContextIOS(AudioContextIOS Function() buildContextIOS) {
104+
try {
105+
final context = buildContextIOS();
106+
setState(() {
107+
audioContext = audioContext.copy(iOS: context);
108+
});
109+
} on AssertionError catch (e) {
110+
toast(e.message.toString());
111+
}
101112
}
102113

103114
Widget _genericTab() {
@@ -112,11 +123,13 @@ class AudioContextTabState extends State<AudioContextTab>
112123
audioContextConfig.copy(route: v),
113124
),
114125
),
115-
Cbx(
116-
'Duck Audio',
117-
value: audioContextConfig.duckAudio,
118-
({value}) => updateConfig(
119-
audioContextConfig.copy(duckAudio: value),
126+
LabeledDropDown<AudioContextConfigFocus>(
127+
label: 'Audio Focus',
128+
key: const Key('audioFocus'),
129+
options: {for (final e in AudioContextConfigFocus.values) e: e.name},
130+
selected: audioContextConfig.focus,
131+
onChange: (v) => updateConfig(
132+
audioContextConfig.copy(focus: v),
120133
),
121134
),
122135
Cbx(
@@ -194,19 +207,20 @@ class AudioContextTabState extends State<AudioContextTab>
194207
Widget _iosTab() {
195208
final iosOptions = AVAudioSessionOptions.values.map(
196209
(option) {
197-
final options = audioContext.iOS.options;
210+
final options = {...audioContext.iOS.options};
198211
return Cbx(
199212
option.name,
200213
value: options.contains(option),
201214
({value}) {
202-
if (value ?? false) {
203-
options.add(option);
204-
} else {
205-
options.remove(option);
206-
}
207-
updateAudioContextIOS(
208-
audioContext.iOS.copy(options: options),
209-
);
215+
updateAudioContextIOS(() {
216+
final iosContext = audioContext.iOS.copy(options: options);
217+
if (value ?? false) {
218+
options.add(option);
219+
} else {
220+
options.remove(option);
221+
}
222+
return iosContext;
223+
});
210224
},
211225
);
212226
},
@@ -219,7 +233,7 @@ class AudioContextTabState extends State<AudioContextTab>
219233
options: {for (final e in AVAudioSessionCategory.values) e: e.name},
220234
selected: audioContext.iOS.category,
221235
onChange: (v) => updateAudioContextIOS(
222-
audioContext.iOS.copy(category: v),
236+
() => audioContext.iOS.copy(category: v),
223237
),
224238
),
225239
...iosOptions,

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class _ControlsTabState extends State<ControlsTab>
159159
txt: 'Custom',
160160
onPressed: () async {
161161
dialog(
162-
SeekDialog(
162+
_SeekDialog(
163163
value: modalInputSeek,
164164
setValue: (it) => setState(() => modalInputSeek = it),
165165
seekDuration: () => _seekDuration(
@@ -184,18 +184,17 @@ class _ControlsTabState extends State<ControlsTab>
184184
bool get wantKeepAlive => true;
185185
}
186186

187-
class SeekDialog extends StatelessWidget {
187+
class _SeekDialog extends StatelessWidget {
188188
final VoidCallback seekDuration;
189189
final VoidCallback seekPercent;
190190
final void Function(String val) setValue;
191191
final String value;
192192

193-
const SeekDialog({
193+
const _SeekDialog({
194194
required this.seekDuration,
195195
required this.seekPercent,
196196
required this.value,
197197
required this.setValue,
198-
super.key,
199198
});
200199

201200
@override
@@ -209,7 +208,7 @@ class SeekDialog extends StatelessWidget {
209208
onChange: setValue,
210209
),
211210
Row(
212-
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
211+
mainAxisAlignment: MainAxisAlignment.center,
213212
children: [
214213
Btn(
215214
txt: 'millis',
@@ -232,9 +231,9 @@ class SeekDialog extends StatelessWidget {
232231
seekPercent();
233232
},
234233
),
235-
Btn(
236-
txt: 'Cancel',
234+
TextButton(
237235
onPressed: Navigator.of(context).pop,
236+
child: const Text('Cancel'),
238237
),
239238
],
240239
),

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

Lines changed: 273 additions & 38 deletions
Large diffs are not rendered by default.

packages/audioplayers/example/lib/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extension StateExt<T extends StatefulWidget> on State<T> {
77
ScaffoldMessenger.of(context).showSnackBar(
88
SnackBar(
99
content: Text(message, key: textKey),
10-
duration: const Duration(milliseconds: 250),
10+
duration: Duration(milliseconds: message.length * 25),
1111
),
1212
);
1313
}

packages/audioplayers/example/pubspec.yaml

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

99
dependencies:
10-
audioplayers: ^5.1.0
10+
audioplayers: ^6.1.0
1111
audioplayers_tizen:
1212
path: ../
1313
collection: ^1.16.0
1414
file_picker: ^5.0.1
1515
flutter:
1616
sdk: flutter
17-
http: ^0.13.6
18-
path_provider: ^2.0.1
17+
http: ">=0.13.1 <2.0.0"
18+
path_provider: ^2.0.12
1919
path_provider_tizen:
2020
path: ../../path_provider/
2121
provider: ^6.0.5

packages/audioplayers/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ flutter:
1616
fileName: audioplayers_tizen_plugin.h
1717

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

packages/audioplayers/tizen/src/audio_player.cc

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99

1010
AudioPlayer::AudioPlayer(const std::string &player_id,
1111
PreparedListener prepared_listener,
12-
CurrentPositionListener current_position_listener,
1312
DurationListener duration_listener,
1413
SeekCompletedListener seek_completed_listener,
1514
PlayCompletedListener play_completed_listener,
1615
LogListener log_listener)
1716
: player_id_(player_id),
1817
prepared_listener_(prepared_listener),
19-
current_position_listener_(current_position_listener),
2018
duration_listener_(duration_listener),
2119
seek_completed_listener_(seek_completed_listener),
2220
play_completed_listener_(play_completed_listener),
23-
log_listener_(log_listener) {}
21+
log_listener_(log_listener) {
22+
CreatePlayer();
23+
}
2424

2525
AudioPlayer::~AudioPlayer() { Release(); }
2626

@@ -32,10 +32,6 @@ void AudioPlayer::Play() {
3232
return;
3333
}
3434

35-
if (state == PLAYER_STATE_NONE) {
36-
CreatePlayer();
37-
}
38-
3935
switch (state) {
4036
case PLAYER_STATE_NONE:
4137
case PLAYER_STATE_IDLE: {
@@ -113,6 +109,7 @@ void AudioPlayer::Release() {
113109
ecore_timer_del(timer_);
114110
timer_ = nullptr;
115111
}
112+
released_ = true;
116113
}
117114

118115
void AudioPlayer::Seek(int32_t position) {
@@ -224,6 +221,16 @@ int AudioPlayer::GetDuration() {
224221
}
225222

226223
int AudioPlayer::GetCurrentPosition() {
224+
// TODO(jsuya) : When stop() or pause() is called in AudioPlayer 6.1.0,
225+
// PositionUpdater's stopAndUpdate() is called. At this time, getPosition() is
226+
// called, but in ReleaseMode, the player is released after Stop(), so an
227+
// eception is thrown. Since there are differences from the implementation in
228+
// the frontend package, an exception is not thrown in this case.
229+
if (!player_ && released_ && release_mode_ == ReleaseMode::kRelease) {
230+
LOG_ERROR("The player has already been released.");
231+
return 0;
232+
}
233+
227234
int32_t position;
228235
int ret = player_get_play_position(player_, &position);
229236
if (ret != PLAYER_ERROR_NONE) {
@@ -263,6 +270,8 @@ void AudioPlayer::CreatePlayer() {
263270
throw AudioPlayerError("player_set_error_cb failed",
264271
get_error_message(ret));
265272
}
273+
274+
released_ = false;
266275
}
267276

268277
void AudioPlayer::PreparePlayer() {
@@ -434,8 +443,6 @@ Eina_Bool AudioPlayer::OnPositionUpdate(void *data) {
434443
if (player->IsPlaying()) {
435444
int32_t duration = player->GetDuration();
436445
player->duration_listener_(player->player_id_, duration);
437-
int32_t position = player->GetCurrentPosition();
438-
player->current_position_listener_(player->player_id_, position);
439446

440447
return ECORE_CALLBACK_RENEW;
441448
}

0 commit comments

Comments
 (0)