Skip to content

Commit 6b8bd4f

Browse files
committed
Bug fix: reset audio sources when restarting from completed state
1 parent bd0b260 commit 6b8bd4f

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

lib/providers/audio_handler.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,29 @@ class DlnaAudioHandler extends BaseAudioHandler with QueueHandler, SeekHandler {
257257
}
258258

259259
Future<void> playIndex(int index) async {
260-
if (index >= 0 && index < (queue.value.length)) {
260+
if (index < 0 || index >= queue.value.length) return;
261+
262+
// After the playlist has finished, the player sits in
263+
// ProcessingState.completed. seek+play resumes audio but just_audio's
264+
// position/duration streams don't reliably restart their periodic
265+
// emissions — slider and time stay at 00:00. Re-setting the audio
266+
// sources gives a fresh stream state.
267+
if (_player.processingState == ProcessingState.completed) {
268+
final audioSources = queue.value.map((item) {
269+
return AudioSource.uri(
270+
Uri.parse(item.extras!['trackUrl'] as String),
271+
tag: item,
272+
);
273+
}).toList();
274+
await _player.setAudioSources(
275+
audioSources,
276+
initialIndex: index,
277+
initialPosition: Duration.zero,
278+
);
279+
} else {
261280
await _player.seek(Duration.zero, index: index);
262-
await _player.play();
263281
}
282+
await _player.play();
264283
}
265284

266285
@override

0 commit comments

Comments
 (0)