1 Unstar Star 0 Fork 0

YangBin / flutter-music-player

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

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.

Comments ( 0 )

Sign in for post a comment

About

Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
1
https://gitee.com/summerly/flutter-music-player.git
git@gitee.com:summerly/flutter-music-player.git
summerly
flutter-music-player
flutter-music-player
master

Search

132457 8cb2edc1 1899542 131848 70c8d3a4 1899542