1 Star 0 Fork 0

YangBin / flutter-music-player

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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.

MIT License Copyright (c) 2019 伯言 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.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
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

搜索帮助