I want to save the current track and time location in a Just Audio playlist in a flutter app.
My current thought is to save the location using something like
_audioPlayer.positionStream.listen((event) {
// update the progress bar in the UI
// save the location using SharedPreferences
});
but I am afraid that this will use a lot of battery life since this function will be run every 16 ms-200 ms. Is there any way to check the battery drain of this one function? And is there any way to save time, but not as often? Would it for instance be better to create another position stream that only runs every 5 seconds? Is there any super failsafe way of saving the location when the user exits the app? Could the solution be to just use another and faster library than SharedPreferences, like hive?