gafsel / flutter_plugin_playlist

A Flutter plugin for Android and iOS with native support for audio playlists, background support, and lock screen controls
MIT License
23 stars 8 forks source link

flutter_plugin_playlist

A Flutter plugin for Android and iOS with native support for audio playlists, background support, and lock screen controls.

IMPORTANT

First of all, I'd like to thank codinronan for the exceptional work on the original plugin. It made my work with my apps a lot easier.

This plugin is an adaptation of cordova-plugin-playlist to a Flutter plugin. The native source code and the documentation was based on it.

0. Index

  1. Notes
  2. Installation
  3. Usage
  4. Todo
  5. Credits
  6. License

1. Notes

On Android, utilizes a wrapper over ExoPlayer called ExoMedia. ExoPlayer is a powerful, high-quality player for Android provided by Google

On iOS, utilizes a customized AVQueuePlayer in order to provide feedback about track changes, buffering, etc.; given that AVQueuePlayer can keep the audio session running between songs.

2. Installation

Add flutter_plugin_playlist as a dependency in pubspec.yml

For help on adding as a dependency, view the documentation.

Background Mode

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

3. Usage

Import the library with:

import 'package:flutter_plugin_playlist/flutter_plugin_playlist.dart';

Use the class RmxAudioPlayer for interacting directly with the plugin.

RmxAudioPlayer player = new RmxAudioPlayer();

player.initialize();

player.on('status', (eventName, {dynamic args}) {

   // TODO handle the status update

});

rmxAudioPlayer.setPlaylistItems(
        [
          new AudioTrack(
              album: "Friends",
              artist: "Bon Jovi",
              assetUrl: "https://www.soundboard.com/mediafiles/22/223554-d1826dea-bfc3-477b-a316-20ded5e63e08.mp3",
              title: "I'll be there for you"
          ),
          new AudioTrack(
              album: "Friends",
              artist: "Ross",
              assetUrl: "assets://assets/223554-fea5dfff-6c80-4e13-b0cf-9926198f50f3.mp3",
              title: "The Sound"
          ),
          new AudioTrack(
              album: "Friends",
              artist: "Friends",
              assetUrl: "https://www.soundboard.com/mediafiles/22/223554-3943c7cb-46e0-48b1-a954-057b71140e49.mp3",
              title: "F.R.I.E.N.D.S"
          ),
        ],
        options: new PlaylistItemOptions(
          startPaused: true,
        )
    );

rmxAudioPlayer.play();  

These are the available resources:

Make sure to check the example and also the original cordova plugin for more details.

For Android, you can replace the notification icon by adding it at res/mipmap/icon.png.

4. Todo

A fast adaptation was the easier solution to my specific needs, so there is lots to improve in the dart code, like creating flutter widgets to encapsulate the service manipulation.

Any evolutions are welcome.

Plus, what was mapped by cordova-plugin-playlist:

There's so much more to do on this plugin. Some items I would like to see added if anyone wants to help:

5. Credits

As already mentioned, this plugin is an adaptation of cordova-plugin-playlist:

6. License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.