How to play a song or podcast from a URL
Updated for Flutter 2.5 and Just Audio 0.9.15 on November 2, 2021
In my last article, Playing short audio clips in Flutter with Just Audio, I demonstrated how to set up Just Audio and play audio clips that only last a few seconds. If you’re new to the Just Audio plugin, I recommend you go through that tutorial first.
This tutorial will demonstrate how to play long-form audio like songs, podcasts, or lectures. While it’s completely possible to play these from files stored on the user’s device, a more common scenario is to stream them based on a URL link, so that’s the direction this tutorial will go. Most of what you learn will also apply to playing a local file, though.
In order to keep this tutorial focused, it will only cover basic topics like playing, pausing, buffering, and seeking in a single audio file. For a full-fledged app, you would also want to implement playlists and background audio, but those topics will have to wait for another tutorial.
If you get lost along the way you can refer to the project source code here.
Setup
Rather than describe the detailed setup process here, I’ll just briefly mention the steps. Refer to the documentation and my previous tutorial…