📚 Encyclopedia

Flutter & Mobile · updated 2026-10-13

just_audio in Flutter, gotchas and patterns

flutterjust_audioaudioandroidriverpod

just_audio (0.10 at the time of writing) is the standard Flutter audio player package, with just_audio_background adding the Android/iOS media notification and lock-screen controls. These are the traps found while building a streaming music player (~/dev/music, Flutter 3.41, Riverpod 3) in July 2026.

API gotchas

Android setup (Android 14+)

just_audio_background needs all three, or the foreground service crashes or never starts: - <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/> - android:foregroundServiceType="mediaPlayback" on the audio service in the manifest - MainActivity extends AudioServiceActivity instead of FlutterActivity

just_audio_background is native-only; guard its init so web builds skip it.

Session resume pattern

Persist queue, trackId, and positionMs in shared preferences and restore them paused on launch. Save position every ~10 s while playing and on the playing to paused transition only. A naive "save whenever not playing" listener fires during the restore load (position 0, not playing) and overwrites the saved position with zero. This was caught only by an end-to-end headless Chrome check.

See also

Linked from

Sources: music project memory