Skip to content

[WIP] play music queue in flutter. this project is extremely experimental.

License

Notifications You must be signed in to change notification settings

boyan01/flutter-music-player

Repository files navigation

flutter_music_player

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.

Getting Started

1. Requirements

  • flutter: 1.20.x stable version
  • android: kotlin 1.4.0
  • ios: 10.0

2. Simple Use Case.

// 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);

3. Background Control.

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

thanks jorgenhenrichsen/SwiftAudio for iOS support.

thanks JetBrain provide open source lincese AppCode for iOS programming.

About

[WIP] play music queue in flutter. this project is extremely experimental.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •