Skip to content

Commit d5a63f8

Browse files
kubitoGustl22
andauthored
feat: Customizable preparation and seeking timeout (#1921)
Added customizable timeout used for seeking and preparation of the player. Closes #1920 --------- Co-authored-by: August <git@reb0.org>
1 parent e8f86e7 commit d5a63f8

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packages/audioplayers/lib/src/audioplayer.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const _uuid = Uuid();
1919
/// hooks for handlers and callbacks.
2020
class AudioPlayer {
2121
static final global = GlobalAudioScope();
22+
static Duration preparationTimeout = const Duration(seconds: 30);
23+
static Duration seekingTimeout = const Duration(seconds: 30);
24+
2225
final _platform = AudioplayersPlatformInterface.instance;
2326

2427
/// This is the [AudioCache] instance used by this player.
@@ -291,7 +294,7 @@ class AudioPlayer {
291294
await creatingCompleter.future;
292295

293296
final futureSeekComplete =
294-
onSeekComplete.first.timeout(const Duration(seconds: 30));
297+
onSeekComplete.first.timeout(AudioPlayer.seekingTimeout);
295298
final futureSeek = _platform.seek(playerId, position);
296299
// Wait simultaneously to ensure all errors are propagated through the same
297300
// future.
@@ -357,7 +360,7 @@ class AudioPlayer {
357360

358361
final preparedFuture = _onPrepared
359362
.firstWhere((isPrepared) => isPrepared)
360-
.timeout(const Duration(seconds: 30));
363+
.timeout(AudioPlayer.preparationTimeout);
361364
// Need to await the setting the source to propagate immediate errors.
362365
final setSourceFuture = setSource();
363366

0 commit comments

Comments
 (0)