Member-only story

Playing short audio clips in Flutter with Just Audio

Suragch
5 min readApr 23, 2021

This article was updated on March 4, 2024 for Flutter 3.19.

There are a million variables when talking about playing audio in a Flutter app, so this tutorial will seek to limit the scope to one basic task: playing short audio clips. Short audio clips don’t require a background service, setting a playlist, seeking to some position, buffering, or adjusting playback speed. That makes this an ideal topic for your first audio tutorial in Flutter.

There are a number of audio packages on Pub, but this tutorial will be using Just Audio. It supports Android, iOS, web, macOS, Windows, and Linux.

Short audio clips are used in many types of apps. Here are a few examples:

  • Game sounds
  • Button click sounds
  • Language learning app
  • Dictionary with recorded audio

These sounds are all likely to be just a few seconds long at the most. You can also use Just Audio to play longer media items like songs and podcasts, but this tutorial won’t cover that today.

Follow along step by step to get the most out of this lesson.

Setup

Creating the UI layout

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Suragch
Suragch

Written by Suragch

Flutter and Dart developer. Twitter: @suragch1, Email: suragch@suragch.dev

Responses (4)

Write a response

I am getting the error in andrioid for files added as local assets. Same audio file is working file when used as network asset.
Error
```
Caused by: com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors…

Thank you very much for explaining Just Audio. It helps a lot for me to use.
Here I have one question.
I also went through your article of "Streaming audio ". However, I could not understand Why this "Playing short audio clips" can not play long…

I am building a desktop application in Windows platform. When I click the button first time the audio plays but if I click it again, the audio file does not play. Also, if one button is clicked, the audio plays and then if I click another button…