flutter_audio_as_service 0.2.1

A Flutter plugin by Tailosive Development (@TailosiveDev) created by Karol WÄ…sowski (@KarolWasowski) Licensed under the BSD License

We are now accepting feature and pull requests.

The plugin is Android only as of now.

1. Before you begin #

Add this permission to AndroidManifest.xml:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

Make sure your app uses Java8 by adding this code into your app-level build.gradle into the android section:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8

Enable androidx support in your app.

Add the service to AndroidMainfest.xml


2. Usage #

To start playback initialize the player with the following:

FlutterAudioAsService.init("Title", "Author", audioSource, appIcon, albumCover);

audioSource is a string - could be both a url or a file directory.

How to properly set appIcon and albumCover:

  • put the desired .png image into android/src/main/res/drawable/
  • if your resource is app_icon.png then set the appIcon value to be "app_icon"
  • the value can be null

If you wish you can set event listeners as follows:

AudioPlayerListener listener = AudioPlayerListener(
  onPlayerStateChanged: (PlayerState playerState) {
  onPlayerPositionChanged: (Duration playerPosition) {
  onPlayerCompleted: () {
    print("Player completed");


Playback is controlled with the following functions:


During playback you may also seek with:

FlutterAudioAsService.seekBy(Duration(seconds: 30));
FlutterAudioAsService.seekTo(Duration(minutes: 15, seconds: 47));

To stop playback and destroy the service run:


3. Features #

The plugin supports audio playback as an Android service with caching functionality included. It uses ExoPlayer with MediaSession API and rich notification controls.

0.2.1 #

  • Stability improvements

0.2.0 #

  • The service now gets bound to the flutter app and unbinds automatically. This improves background performance and stability

0.1.3 #

  • Updated documentation

0.1.2 #

  • Updated example
  • Fixed seekTo() throwing error

0.1.1 #

  • Prevented running functions on null object references
  • If player initialized with source that is already playing player won't start over - it will keep playing
  • getAudioLength() now returns 0 if player is idle

0.1.0 #

Minor changes, improved consistency

0.0.4 #

Added listeners to player state changes, audio position changes and audio completed playing. This will be released as 0.1.0 after some testing.

0.0.3 #

Adds missing feature - set notification album cover, and makes the plugin release-ready (beta)

0.0.2 #

Offers basic functionality with support for starting a service and notification controls.

0.0.1 #

Offers basic playback functionality without starting a service.


flutter_audio_as_service_example #

Demonstrates how to use the flutter_audio_as_service plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_audio_as_service: ^0.2.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_audio_as_service/flutter_audio_as_service.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

This package is not analyzed, because it is discontinued.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0