bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
2.01k stars 845 forks source link

fix: Wait for seek to complete #1712

Closed Gustl22 closed 11 months ago

Gustl22 commented 11 months ago

Description

Wait for seek to finish by listening to the AudioEventType.seekComplete event.

Checklist

Related Issues

Gustl22 commented 11 months ago

Is it ok to merge? I added quite a lot commits since your review @spydon :)

japostoles commented 8 months ago

If the AudioPlayer is in a stopped state, the seek function will never complete, and the TimeoutException will fire 30 seconds later. ([ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: TimeoutException after 0:00:30.000000: Future not completed)

Any code after the seek will not be executed. From the perspective of a user of the library, the application will hang 30 seconds before registering an unhandled exception.

Sample code:

    var player = AudioPlayer();
    await player.setSource(DeviceFileSource(SomeAudioFile));
    await player.resume();
    sleep(Duration(seconds:1));
    await player.stop();
    print('-SEEK-');
    await player.seek(Duration(seconds:15));      // --- HANGS FOR DURATION OF TIMEOUT HERE
    print('-SEEK FINISH-');