How to Build a Music Player in Flutter as quick as possible
In this article, I will walk you through making a simple Music Player Mobile App Using Flutter.
Flutter is Google’s mobile UI framework that lets you quickly build native mobile apps with one single code base also flutter is 100% free and open source. if you want to learn more about flutter you can find more here.
So over the past two months, I have been working on an ios app. for streaming Music. so I anded to explore the same app with flutter uniformity at the date of creating this tutorial there project is not fully supported for the Ios. this project is only supported by ANDROID
So as always let’s take a look on the UI, the final app should look like the image down below to make this tutorial a simple as possible I will skip this Part but you can find the full code down below
the UI elements used are :

So how to play music? 🤔
So you may be found out that the Flutter SDK doesn’t have support for playing audio/music by Searching through the docs!
but looking throw the available packages which were music-related on pub.dev you may be able to find some available package you can use like
In this demo, I am going to use AudioPlayers plugins which is ready to use plugin to play multiple simultaneously audio files, works for Android and iOS. which works perfectly on this demo There are three possible sources of audio:
- Remote file on the Internet
- Local file on the user’s device
- Local asset from your Flutter project

Install
I will be working with android studio, so as always let’s start by adding the dependency as the time of this tutorial I will be working with version 0.13.2 make sure to click get packages to add the dependencies

Usage
Note: This plugin doesn’t provide any kind of UI for your player we need to build the UI by ourselves
first, go ahead and import the plugin
import 'package:audioplayers/audioplayers.dart';Now we need An AudioPlayer instance so we can play single audio at a time. To create it, simply call the constructor:
AudioPlayer advancedPlayer = AudioPlayer();- Remote file on the Internet first your need to define a sound file valid URL as shown in the example down bellow make sure that is under https protocol if no you need to add a p list exception for ios in order to make it work
const songurlExample = 'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3';️ iOS App Transport Security
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
voilà finally, call audio player.play passing the URL.Run and test
await audioPlayer.play(songurlExample, isLocal: false);I should mention also that there a variety of methods to control the player and event s of duration listener to help you along
here in the full above code
link to the full project here

Thanks for reading! I hope this quick article has helped you in creating your quick audio streaming app

