Skip to content

Commit 57a8c08

Browse files
committedFeb 2, 2021
ok
1 parent 9ed6fb9 commit 57a8c08

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed
 

‎lib/main.dart

+30-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@ class _MyHomePageState extends State<MyHomePage> {
6969
AudioPlayer _player;
7070
bool _isPlaying = false;
7171

72+
List<AudioPlayer> _playersList = List<AudioPlayer>();
73+
74+
75+
void _play5() async {
76+
77+
if (_playersList.length != 0) {
78+
for (final player in _playersList)
79+
player.dispose();
80+
}
81+
82+
// start 5 players with 250 ms delay in between
83+
for (int i = 0; i < 5; ++i) {
84+
AudioPlayer player = AudioPlayer(handleInterruptions: true);
85+
AudioSource audioSource = AudioSource.uri(Uri.parse("asset:///assets/10-second-audio.m4a"));
86+
await player.setAudioSource(audioSource);
87+
await player.setLoopMode(LoopMode.one);
88+
await player.play();
89+
_playersList.add(player);
90+
await Future.delayed(Duration(milliseconds: 250));
91+
}
92+
93+
// trigger refresh
94+
setState(() {
95+
_counter = ++_counter % 10;
96+
});
97+
}
98+
99+
72100

73101
void _playNext() async {
74102
if (_player != null) {
@@ -275,7 +303,8 @@ class _MyHomePageState extends State<MyHomePage> {
275303
),
276304
),
277305
floatingActionButton: FloatingActionButton(
278-
onPressed: _playNext,
306+
onPressed: _play5,
307+
// onPressed: _playNext,
279308
// onPressed: _playLoop,
280309
tooltip: 'Play Next',
281310
child: Icon(Icons.add),

‎pubspec.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ packages:
134134
name: just_audio
135135
url: "https://pub.dartlang.org"
136136
source: hosted
137-
version: "0.6.5"
137+
version: "0.6.9"
138138
just_audio_platform_interface:
139139
dependency: transitive
140140
description:
@@ -148,7 +148,7 @@ packages:
148148
name: just_audio_web
149149
url: "https://pub.dartlang.org"
150150
source: hosted
151-
version: "0.2.1"
151+
version: "0.2.3"
152152
matcher:
153153
dependency: transitive
154154
description:

‎pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies:
3131
# Use with the CupertinoIcons class for iOS style icons.
3232
cupertino_icons: ^1.0.0
3333
path_provider: ^1.6.24
34-
just_audio: ^0.6.5
34+
just_audio: ^0.6.9
3535
# just_audio:
3636
# git:
3737
# # url: https://github.com/ryanheise/just_audio.git

0 commit comments

Comments
 (0)
Please sign in to comment.