Background audio in Flutter with Audio Service and Just Audio

Suragch
35 min readJul 17, 2021

A full step-by-step tutorial

Article updated on March 18, 2023.

If you’re only playing short audio clips in your app, then generally a simple audio player plugin will work. However, for longer audio forms like music or podcasts, this is often insufficient. Let’s say you start playing a podcast but then leave this app to check your fitness app. What does the podcast app do? It could stop the audio as soon as you leave, but you want to keep listening, so that’s not a good option. On the other hand, if the app allows the podcast to keep playing in the background, imagine the second scenario: You’re happily exercising and listening to the podcast when all of a sudden someone knocks on the door. Where’s the pause button? How do you stop the podcast!? Knock, knock, knock! Argh! There’s no stop button! You finally navigate back to the podcast app and find a way to stop the audio. How annoying!

I should know since I made an app like that once.

The Flutter audio_service plugin solves the problems described above by allowing users to listen to audio outside of the app and also by giving users access to system-wide audio control buttons. On Android these buttons are located in the notification drawer and the lock screen. On iOS they are located in the control center and…

--

--