NOTE: this project is extremely experimental.
Media session framework plugin for flutter, make it easy to implement music play by flutter.
- ios support
- media style notification.
- basic media control.
- tracking player status change.
- flutter: 1.20.x stable version
- android: kotlin 1.4.0
- ios: 10.0
// Create Player instance.
MusicPlayer player = MusicPlayer();
// audio list
final medias = [
MusicMetadata(
title: "Zhu Lin Jian",
subtitle: "Zhu Lin Jian - SanWu marblue",
mediaId: "bamboo",
mediaUri: "asset:///tracks/bamboo.mp3",
iconUri: "https://via.placeholder.com/150/FFCA28/000000/?text=bamboo",
),
MusicMetadata(
title: "Rise",
subtitle: "Rise - The Glitch Mob",
mediaId: "rise",
mediaUri: "asset:///tracks/rise.mp3",
iconUri: "https://via.placeholder.com/150/4CAF50/FFFFFF/?text=Rise",
),
MusicMetadata(
title: "Cang",
subtitle: "Cang - xu meng yuan",
mediaId: "hide",
mediaUri: "asset:///tracks/hide.mp3",
iconUri: "https://via.placeholder.com/150/03A9F4/000000/?text=Cang",
),
];
PlayQueue queue = PlayQueue(queueTitle: "Simple Test", queueId: "test1", queue: medias);
// Perform play operation.
player.playWithQueue(queue, metadata: medias.first);
add a method named playerBackgroundService
to your lib/maim.dart.
playerBackgroundService
is background service FlutterEngin entry point.
@pragma("vm:entry-point")
void playerBackgroundService() {
runBackgroundService(
playUriInterceptor: (mediaId, fallbackUrl) async {
debugPrint("get media play uri : $mediaId , $fallbackUrl");
if (mediaId == 'rise') return "asset:///tracks/rise.mp3";
return fallbackUrl;
},
imageLoadInterceptor: (metadata) async {
debugPrint("load image for ${metadata.mediaId} , ${metadata.title}");
if (metadata.mediaId == "bamboo") {
final data = await rootBundle.load("images/bamboo.jpg");
return Uint8List.view(data.buffer);
}
return null;
},
playQueueInterceptor: ExamplePlayQueueInterceptor(),
);
}
thanks jorgenhenrichsen/SwiftAudio for iOS support.
thanks JetBrain provide open source lincese AppCode for iOS programming.