Just audio background - A flutter package plugs into just audio to add background playback support and remote controls

Overview

just_audio_background

This package plugs into just_audio to add background playback support and remote controls (notification, lock screen, headset buttons, smart watches, Android Auto and CarPlay). It supports the simple use case where an app has a single AudioPlayer instance.

If your app has more complex requirements, it is recommended that you instead use the audio_service package directly.

Setup

Add the just_audio_background dependency to your pubspec.yaml alongside just_audio:

dependencies:
  just_audio: any # substitute version number
  just_audio_background: any # substitute version number

Then add the following initialization code to your app's main method:

Future<void> main() async {
  await JustAudioBackground.init(
    androidNotificationChannelId: 'com.ryanheise.bg_demo.channel.audio',
    androidNotificationChannelName: 'Audio playback',
    androidNotificationOngoing: true,
  );
  runApp(MyApp());
}

Create your player as normal:

player = AudioPlayer();

Set a MediaItem tag on each IndexedAudioSource loaded into the player. For example:

AudioSource.uri(
  Uri.parse('https://example.com/song1.mp3'),
  tag: MediaItem(
    // Specify a unique ID for each media item:
    id: '1',
    // Metadata to display in the notification:
    album: "Album name",
    title: "Song name",
    artUri: Uri.parse('https://example.com/albumart.jpg'),
  ),
),

Android setup

Make the following changes to your project's AndroidManifest.xml file:

<manifest ...>
  <!-- ADD THESE TWO PERMISSIONS -->
  <uses-permission android:name="android.permission.WAKE_LOCK"/>
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
  
  <application ...>
    
    ...
    
    <!-- EDIT THE android:name ATTRIBUTE IN YOUR EXISTING "ACTIVITY" ELEMENT -->
    <activity android:name="com.ryanheise.audioservice.AudioServiceActivity" ...>
      ...
    </activity>
    
    <!-- ADD THIS "SERVICE" element -->
    <service android:name="com.ryanheise.audioservice.AudioService">
      <intent-filter>
        <action android:name="android.media.browse.MediaBrowserService" />
      </intent-filter>
    </service>

    <!-- ADD THIS "RECEIVER" element -->
    <receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver" >
      <intent-filter>
        <action android:name="android.intent.action.MEDIA_BUTTON" />
      </intent-filter>
    </receiver> 
  </application>
</manifest>

iOS setup

Insert this in your Info.plist file:

	<key>UIBackgroundModes</key>
	<array>
		<string>audio</string>
	</array>
You might also like...

Tubles is a simple applications to provide any tubles in in google maps and we as the user can navigate into the selected tubles location.

Tubles is a simple applications to provide any tubles in in google maps and we as the user can navigate into the selected tubles location.

Tubles Tubles is a simple applications to provide any tubles place in google maps and we as the user can navigate into the selected tubles location. F

Jan 8, 2023

A simple easy to use Flutter DApp , which keeps a track of all your day to day transactions by using Ethereum blockchain in the background which in turn increases your credit score.

A simple easy to use Flutter DApp , which keeps a track of all your day to day transactions by using Ethereum blockchain in the background which in turn increases your credit score.

Sahayog A simple easy to use Flutter DApp , which keeps a track of all your day to day transactions by using Ethereum blockchain in the background whi

May 21, 2022

A app made with Flutter, which allows user to lookup time of any major city in the world. The UI also changes its background according to the time.

first_flutter_project A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you st

Oct 31, 2021

Amazing Flutter package for playing audio with a lot of features to offer.

Flutter_exoplayer A Flutter plugin that let's you play multiple audio files simultaneously with an option to choose if to play in background or as a f

Aug 7, 2022

A project to showcase usage of basic principles to convert any 3D design into a working application using Flutter.

A project to showcase usage of basic principles to convert any 3D design into a working application using Flutter.

Developing apps with 3D designs in flutter This project is developed to showcase how we can use some basic principles to convert any 3D design into a

Dec 22, 2022

🎡 Elegant music app to play local music & YouTube music. Distributes music into albums & artists. Has playlists & lyrics.

🎡 Elegant music app to play local music & YouTube music. Distributes music into albums & artists. Has playlists & lyrics.

Harmonoid Elegant music app to play local music & YouTube music. Download Now 🏁 Feel free to report bugs & issues. We'll be there to fix. Loving the

Dec 30, 2022

🎡 Elegant music app to play local music & YouTube music. Distributes music into albums & artists. Has playlists & lyrics. Windows + Linux + Android.

🎡 Elegant music app to play local music & YouTube music. Distributes music into albums & artists. Has playlists & lyrics. Windows + Linux + Android.

Harmonoid Elegant music app to play local music & YouTube music. Download Now 🏁 Windows, Linux & Android. Feel free to report bugs & issues. Loving t

Aug 10, 2022

A Simple Todo app design in Flutter to keep track of your task on daily basis. Its build on BLoC Pattern. You can add a project, labels, and due-date to your task also you can sort your task on the basis of project, label, and dates

A Simple Todo app design in Flutter to keep track of your task on daily basis. Its build on BLoC Pattern. You can add a project, labels, and due-date to your task also you can sort your task on the basis of project, label, and dates

WhatTodo Life can feel overwhelming. But it doesn’t have to. A Simple To-do app design in flutter to keep track of your task on daily basis. You can a

Jan 6, 2023

About This is Personal Expenses Planner. You can add your expenses in to the app and manage your transaction. and you can see How much did you spend on which day. I developed this project using flutter.

expense_planner A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Jul 6, 2022
Owner
lonyyy
lonyyy
Audio manager - A flutter plugin for music playback, including notification handling.

audio_manager A flutter plugin for music playback, including notification handling. This plugin is developed for iOS based on AVPlayer, while android

Jerome Xiong 96 Oct 25, 2022
Midi Playback in Flutter

flutter_midi A FLutter Plugin to Play midi on iOS and Android. This uses SoundFont (.sf2) Files. Online Demo: https://rodydavis.github.io/flutter_midi

Rody Davis 50 Nov 5, 2022
A clean front-end to Volumio, the Linux distribution for music playback. DigiPlayer is written in Flutter.

EN | δΈ­ζ–‡ DigiPlayer - A Clean Touch UI for Volumio 3 DigiPlayer is a clean touch UI for Volumio 3, written in Flutter for the Raspberry Pi Touch Displa

Feng Zhou 5 Jul 26, 2022
Flutter ShopApp, you can see products and their prices, categories and their products, search for a product, add to favorite, add to cart, sign in and sign up.

shop_app_2 A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

Muhammed Rezk Rajab 10 Aug 7, 2022
Utility Manager Flutter Application is made with Flutter and Supabase which allows user to add task, set remainder to the task, set color to separate tasks and it allows to add URL with URL's informations.

Utility Manager Flutter Application! Utility Manager Flutter Application is made with Flutter and Supabase which allows user to add task, set remainde

Kathirvel Chandrasekaran 6 Jan 6, 2022
A remote app built using Flutter that creates the users of the specific wordpress website.

wp_users A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

dev_allauddin 3 Feb 3, 2022
This Dart package will utilize the plugin, google_mobile_ads, so to quickly and easily implement ads into a Flutter app.

Ads to your App in a Snap! This Dart package will utilize the plugin, google_mobile_ads, so to quickly and easily implement ads into a Flutter app

Andrious Solutions Ltd. 58 Sep 11, 2022
BankGit helps you manage your account and transactions more efficiently by breaking your account into branches for various purposes and then making transactions directly from them.

Bank Git Web Hosted Here : https://bank-management-45848.web.app/ Bank Git is an application built with Flutter and Firebase to help you manage your b

Yash Johri 27 Dec 26, 2022
Caching with flutter riverpod and looking into future providers. Example to demonstrate stale while revalidate pattern.

FLUTTER SWR EXAMPLE Test stale-while-revalidate pattern with riverpod. Look; query_provider package Backend calls are made with ghibli-api Tested Prov

Dipesh Dulal 7 Jun 30, 2022
Tooling and libraries for processing dart test output into dev-friendly formats

better_test_reporter Introduction This is an application/library heavily inspired by dart-junitreport and dart-testreport. It takes what was done in t

Betterment 6 Sep 14, 2022