Coder Social home page Coder Social logo

boyan01 / flutter-music-player Goto Github PK

View Code? Open in Web Editor NEW
78.0 7.0 38.0 3.32 MB

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

License: MIT License

Kotlin 50.73% Ruby 1.47% Swift 17.72% Objective-C 0.46% Dart 27.73% AIDL 1.47% Java 0.43%

flutter-music-player's Introduction

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.

flutter-music-player's People

Contributors

boyan01 avatar mdddj avatar xsahil03x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter-music-player's Issues

Remove android multi process

 <service
            android:name="tech.soit.quiet.service.MusicPlayerService"
            android:process=":player" />

It is unnessary to support multi process.

Lyrics no scroll

Dear admin,
I 've tried on IOS 13.1.5 but lyrics no scroll.

please help me

  • Updated:
    I replaced

var append = state == PlayerState.Playing ? (SystemClock.uptime().inMilliseconds - updateTime) : 0;

with

var append = state == PlayerState.Playing ? (DateTime.now().millisecondsSinceEpoch - updateTime) : 0 ;

It's ok now. I dont know why that.

support for ios

Hi, thanks so much for the time you're putting on this, I wanted to know that is there any plan for ios support?!

system_clock.h not found

build Error:system_clock.h not found。
var append = state == PlayerState.Playing ? (SystemClock.uptime().inMilliseconds - updateTime) : 0;
===>
var append = state == PlayerState.Playing ? (DateTime.now().millisecondsSinceEpoch - updateTime) : 0;
这里为什么不用这种方式呢?

play mode有问题

播放模式ios有问题 切换三个模式都是循环播放 播放一次的模式也不起作用

Define ticket and boards or milestone (IOS platform)

Can you define milestone and ticket list then, I will pick up it and working with you?

I'm so interested in your project and I don't know to build it my self, But I know some of swfit knowledge and ios.

If you have times please help define what we should do then I do it with you.

Thanks @boyan01 .

Posible to play with set specific time?

How to add custom play loop with single files to specify the time ??

example

new CountDownTimer(30000, 1000) {
 
      public void onTick(long millisUntilFinished) {
         // keep it playing
      }
 
      public void onFinish() {
          // go next 
      }
   }.start(); 

How to automatically update current playing music info ?

In the example, we are showing the current position and all other information of the currently playing music. But they get updated only when the music changes or when we play pause it.

How to make this thing automatic so that we can see the latest current position.

Current duration playing on android working not correct

Updated To work

Rollback https://github.com/boyan01/flutter-music-player/commit/22d84a7c1a6f35a77b0ad8a51ac7035b81dee83b
updateTime = SystemClock.uptimeMillis(),
With
updateTime = System.currentTimeMillis(),


I use your code to play one music with android and ios

https://github.com/boyan01/flutter-netease-music/blob/cdb4e0af75dcd9705de5cd97a95cc1de9185fa39/lib/pages/player/player_progress.dart

IOS Working fine

Screen Shot 2020-08-23 at 8 46 33 PM

Android does not work correctly

current playing duration over end duration position

Screen Shot 2020-08-23 at 8 36 47 PM

Print code

      var position = isUserTracking ? trackingPosition.round() : state.positionWithOffset;


      durationText = getTimeStamp(duration);
      positionText = getTimeStamp(position);

      print("duration: $duration");
      print("duration Playing: $positionText");
      print("End durationText: $durationText");

Android Result on start playing mp3

I/flutter (13917): duration: 277315
I/flutter (13917): duration Playing: 38:21
I/flutter (13917): End durationText: 04:37

IOS Result on start playing mp3

Restart device when first time click item to play.

I do release apk and install on real device Samsung 2Galaxy S8 and Galaxy S9 running android 8.0 It is the same result.

Launch home with list items working well but when I try to click play item then It restart my phone.

Because of copyright this library?

Very slow streaming music from remote url

I use assets mp3 it is so faster. but when I use remote mp3 it is very slow both android and ios. But ios is the slowest.

1). I run flutter run --profile for testing on ios real device and it task long time to start playing.
2). seek is not work

How to resolve it?

I use medias

final medias = [
  
];

插件不支持.flac文件

大佬,这个插件不支持flac格式吗?

W/MediaAnalyticsItem(31974): Unable to record: (codec:0:-1:-11:0:5:android.media.mediacodec.codec=OMX.google.mp3.decoder:android.media.mediacodec.mode=audio:android.media.mediacodec.secure=0:android.media.mediacodec.mime=audio/mpeg:android.media.mediacodec.bytesin=1563167:) [forcenew=0]
I/flutter (31974): load image for 11334 , 有你
I/flutter (31974): get media play uri : 11334 , /storage/emulated/0/netease/cloudmusic/Music/王愚 陈娅琪 - 有你 .flac
I/flutter (31974): load image for 11334 , 有你
I/flutter (31974): load image for 11334 , 有你
E/ExoPlayerImplInternal(31974): Source error.
E/ExoPlayerImplInternal(31974): com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor, AmrExtractor) could read the stream.
E/ExoPlayerImplInternal(31974): 	at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:973)
E/ExoPlayerImplInternal(31974): 	at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:891)
E/ExoPlayerImplInternal(31974): 	at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
E/ExoPlayerImplInternal(31974): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
E/ExoPlayerImplInternal(31974): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
E/ExoPlayerImplInternal(31974): 	at java.lang.Thread.run(Thread.java:764)
I/flutter (31974): load image for 11334 , 有你
I/flutter (31974): load image for 11334 , 有你

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.