flutter_audio_as_service 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

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

<manifest>
  ...
  <application>
    ...
    ...
    <service 
      android:name="net.tailosive.flutter_audio_as_service.AudioService"/>
  </application>
</manifest>

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) {
    print(playerState);
  },
  onPlayerPositionChanged: (Duration playerPosition) {
    print(playerPosition.toString());
  },
  onPlayerCompleted: () {
    print("Player completed");
  }
);

FlutterAudioAsService.setListeners(listener);

Playback is controlled with the following functions:

FlutterAudioAsService.pause();
FlutterAudioAsService.resume();

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:

FlutterAudioAsService.stop();

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.

example/README.md

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:


dependencies:
  flutter_audio_as_service: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Nov 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/flutter_audio_as_service.dart.

Run flutter format to format lib/flutter_audio_as_service.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test