I’m trying to implement audio recording and playback in my app.
For the playback, I’m trying to use the package flutter_sound. I’m using version 9.2.13
because of a dependency conflict with objectbox
, so I can’t seem to use newer version.
Anyways, what I want to do is implement a slider that follows playback and allows to scroll through the recording. The documentation hints at the existence of a SoundPlayerUI
widget but I can’t use it, so I opted for a regular Slider.
When creating the view for the playback, I create a FlutterSoundPlayer
and I setup a subscription to the “onProgress” stream that I use to track audio playback and update my slider ui:
player.onProgress?.listen((e) {
if(maxDuration == Duration.zero) maxDuration = e.duration;
position = e.position;
sliderValue =(position.inMilliseconds / maxDuration.inMilliseconds) * 100;
log("Max duration is: $maxDuration, current position is ${e.position}");
notifyListeners();
});
So with that code, I should get a PlaybackDisposition that allows me to update position
through the stream and have a smooth animation with my slider slowly filling up from 0 to 100. The problem is that the position
value seems to rollback randomly, for no reason and with no impact on the actual playback. Let’s look at the logs:
[log] Max duration is: 0:00:07.531000, current position is 0:00:00.109000
[log] Max duration is: 0:00:07.531000, current position is 0:00:00.208000
[log] Max duration is: 0:00:07.531000, current position is 0:00:00.310000
[log] Max duration is: 0:00:07.531000, current position is 0:00:00.411000
[log] Max duration is: 0:00:07.531000, current position is 0:00:00.512000
[log] Max duration is: 0:00:07.531000, current position is 0:00:00.612000
[log] Max duration is: 0:00:07.531000, current position is 0:00:00.201000
[log] Max duration is: 0:00:07.531000, current position is 0:00:00.303000
So as you can see the position value, which is supposed to track playback progress, goes from 0.6s to 0.2s for no reason and without disruption the playback.
This means that the Slider UI looks like the track rewinds when it’s not, and that the max duration information is wrong by about 0.6 seconds. This rollback value seems random, though usually stays below the 1s mark.
Any idea why that happens and how to fix it ?
File format: M4A
Android APK 33, ext.kotlin_version = ‘1.8.10’ (doesn’t compile with 1.9+).