Last updated:
0 purchases
flutter audio service
flutter_audio_service #
A Flutter plugin by Tailosive Development (@TailosiveDev) created by Karol Wąsowski (@KarolWasowski)
Licensed under the BSD License
This package was first released as flutter_audio_as_service, but was later renamed because of issues with pub.dev
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"/>
copied to clipboard
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
}
copied to clipboard
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>
copied to clipboard
2. Usage #
To start playback initialize the player with the following:
AudioInfo info = AudioInfo(
"Title",
"Author",
audioUrl,
coverUrl,
drawableAppIcon
)
FlutterAudioAsService.init(info);
copied to clipboard
audioUrl and coverUrl are strings - could be both urls or a file directories (file:///)
How to properly set appIcon
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);
copied to clipboard
Playback is controlled with the following functions:
FlutterAudioAsService.pause();
FlutterAudioAsService.resume();
copied to clipboard
During playback you may also seek with:
FlutterAudioAsService.seekBy(Duration(seconds: 30));
FlutterAudioAsService.seekTo(Duration(minutes: 15, seconds: 47));
copied to clipboard
To stop playback and destroy the service run:
FlutterAudioAsService.stop();
copied to clipboard
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.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.