A Flutter plugin for playing music on iOS and Android.

Overview

Stereo plugin for Flutter

A Flutter plugin for playing music on iOS and Android.

Features

  • Play/pause
  • Stop
  • Duration / seek to position
  • Load track from path
  • Load track from library

Installation

First, add stereo as a dependency in your pubspec.yaml file.

Android

Add the following permission to your AndroidManifest.xml file:

  • <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

iOS

Add the following key to your Info.plist file:

  • NSAppleMusicUsageDescription

Example

See the example documentation for more information.

Changelog

See CHANGELOG.md.

Contributing

Feel free to contribute by opening issues and/or pull requests. Your feedback is very welcome!

License

This project is licensed under the MIT License. See LICENSE file for more information.

Credits

Stereo has been developed and is maintained by faku99, ludelafo and Daxidz.

In no particular order, we credit the following people for their invaluable contributions:

Comments
  • Add a method that shows an UI to pick an audio file from storage

    Add a method that shows an UI to pick an audio file from storage

    The library should be able to show a simple UI to pick an audio file from storage.

    I think of the following method signature:

    • Future<AudioFile> showPicker() - opens a simple picker for an audio file. The type AudioFile is the same as defined in #8.
    opened by faku99 5
  • Need some cleanup in repo

    Need some cleanup in repo

    I think we need to cleanup some files and code lines.

    For example, in the following classes, MCMediaPickerController.h and MCMediaPickerController.m use the word MC, which was our first organization's name.

    And here, audio_player is still used.

    Shouldn't we rename all of these to relate more to stereo (if stereo is definitive ?) ? I haven't checked all the repo, at the moment.

    opened by ludelafo 5
  • Add a method to load an audio file

    Add a method to load an audio file

    The library should be able to load an audio file to be played.

    I see the following methods:

    • void load(String) - load the audio file from a string representing the URI to the file
    • void load(URI) - load the audio file from an URI pointing to the file
    • void load(AudioFile) - load the audio file directly from an audio file

    The two firsts methods would call the later one to avoid redundancy.

    These methods should throw an exception if the audio file can't be loaded.

    enhancement 
    opened by ludelafo 4
  • RuntimeException: Selecting an audio file

    RuntimeException: Selecting an audio file

    Hi There

    After selecting an audio file the app crashes

    The code I'm using is

    Future<Null> _selectAudio(BuildContext context) async {
        print("Selecting audio");
        try {
          var track = await _stereo.picker();  
          File newFile = File(track.path);
          print(newFile.length());
        } catch (e) {
          print(e);
        }
      }
    

    The exception is

    Shutting down VM
    FATAL EXCEPTION: main
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.externalstorage.documents/document/3430-6463:Android/output/Afrik.mp3 flg=0x1 }} to activity {com.example.mobile/com.example.mobile.MainActivity}: java.lang.IllegalArgumentException
    E/AndroidRuntime(18479): at android.app.ActivityThread.deliverResults(ActivityThread.java:3742)
    E/AndroidRuntime(18479): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:3785)
    E/AndroidRuntime(18479): 	at android.app.ActivityThread.access$1400(ActivityThread.java:157)
    E/AndroidRuntime(18479): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
    E/AndroidRuntime(18479): 	at android.os.Handler.dispatchMessage(Handler.java:102)
    E/AndroidRuntime(18479): 	at android.os.Looper.loop(Looper.java:148)
    E/AndroidRuntime(18479): 	at android.app.ActivityThread.main(ActivityThread.java:5527)
    E/AndroidRuntime(18479): 	at java.lang.reflect.Method.invoke(Native Method)
    E/AndroidRuntime(18479): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
    E/AndroidRuntime(18479): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
    E/AndroidRuntime(18479): Caused by: java.lang.IllegalArgumentException
    E/AndroidRuntime(18479): 	at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:73)
    E/AndroidRuntime(18479): 	at com.twofind.stereo.AudioTrack.toJson(AudioTrack.java:14)
    E/AndroidRuntime(18479): 	at com.twofind.stereo.StereoPlugin.onActivityResult(StereoPlugin.java:242)
    E/AndroidRuntime(18479): 	at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:194)
    E/AndroidRuntime(18479): 	at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:146)
    E/AndroidRuntime(18479): 	at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:139)
    E/AndroidRuntime(18479): 	at android.app.Activity.dispatchActivityResult(Activity.java:6463)
    E/AndroidRuntime(18479): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:3738)
    

    The audio file I'm selecting is in external storage, I moved it to internal and still got the same error.

    opened by knightebsuku 2
  • Add a method to unload an audio file

    Add a method to unload an audio file

    The library should be able to unload an audio file. I see the following method:

    • void unload() - unload the audio file

    This method should throw an exception if the audio file can't be unloaded.

    enhancement 
    opened by ludelafo 2
  • Add a method to toggle play/pause state

    Add a method to toggle play/pause state

    The library should be able to play/pause an audio file.

    When an audio file is playing, calling this method should pause the audio file and when an audio file is in pause, calling this method should play/resume the audio file.

    I see the following method:

    • void togglePlaying() - toggle the play/pause state

    This method should throw an exception if the audio file can't have its play/pause state changed.

    enhancement 
    opened by ludelafo 2
  • Add a class that represents a song

    Add a class that represents a song

    First of all, what should we name it? I was thinking of something like Track, Song, StereoItem, MediaItem. Please let me know if you have other ideas.

    What information should this class hold? Here are some thoughts:

    • Title
    • Artist
    • Album
    • URI
    • Length
    • Artwork URI
    opened by faku99 2
  • iOS build fail

    iOS build fail

    I'm getting the following error message when I try to run the Stereo example on iOS

    Failed to build iOS app Error output from Xcode build: ↳ ** BUILD FAILED **

    Xcode's output: ↳ === BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug === /Users/leehunter/Documents/GitHub/stereo/example/ios/Runner/GeneratedPluginRegistrant.m:13:4: error: unknown receiver 'STStereoPlugin'; did you mean 'StereoPlugin'? [STStereoPlugin registerWithRegistrar:[registry registrarForPlugin:@"STStereoPlugin"]]; ^~~~~~~~~~~~~~ StereoPlugin In file included from /Users/leehunter/Documents/GitHub/stereo/example/ios/Runner/GeneratedPluginRegistrant.m:7: /Users/leehunter/Documents/GitHub/stereo/example/ios/Pods/Headers/Public/stereo/StereoPlugin.h: 5:12: note: 'StereoPlugin' declared here @interface StereoPlugin : NSObject ^ 1 error generated.

    Could not build the application for the simulator. Error launching application on iPhone XR.

    opened by LeeHunter 1
  • Only demo mp3 files can be played in the example app

    Only demo mp3 files can be played in the example app

    In the example app, I can only play the sample files and no others. So far I've tried to load four MP3 files (i.e. by changing the yaml file and main.dart) and I get the "File not playable" message each time I tried to load the file.

    This happens even if I leave the example app code the same but simply rename my substitute files to dubstep.mp3.

    opened by LeeHunter 1
  • Fix recorder interference

    Fix recorder interference

    Because the stereo library initiates a playback session on loading of the application, apps that want to use this with a recording library will fail on a physical iPhone. See https://stackoverflow.com/questions/50687163/how-can-i-track-down-interference-between-the-flutter-libraries-audo-recorder-an

    This change defers the initiating of the audio playback session until it is needed so that it doesn't interfere when another library needs to initiate an audio recording session.

    opened by joelfaul 1
  • Basic display & picker implementations

    Basic display & picker implementations

    This pull request adds the following method to the library:

    • Future<AudioTrack> picker(): shows an UI to pick a track from storage (closes #26)

    It also adds the following members:

    • ValueNotifier<AudioTrack> currentTrackNotifier: notifies listeners every time the playing track changes.
    • AudioTrack currentTrack: current playing track.

    The class AudioTrack has been added (closes #8). It currently represents a track with the following fileds:

    • String album
    • String artist
    • Uint8List artwork
    • String path
    • String title

    The example has been updated to reflect library changes.

    opened by faku99 1
  • AudioTrack.java MediaMetadataRetriever setDataSource throwing IllegalArgumentException

    AudioTrack.java MediaMetadataRetriever setDataSource throwing IllegalArgumentException

    Currently trying to use stereo to play background music in my app and I keep receiving issues whenever I call the load(String) from the Stereo.dart class.

    Whenever I looked further into the issue I figured out that the issue comes directly from the AudioTrack.java class whenever this line is called

    mmr.setDataSource(path);

    To replicate the issue, just add this code into the example project.

    import 'dart:io';
    
    import 'package:flutter/material.dart';
    import 'package:flutter/services.dart';
    import 'package:path_provider/path_provider.dart';
    import 'package:stereo/stereo.dart';
    
    void main() {
      runApp(new MaterialApp(home: new ExampleApp()));
    }
    
    class ExampleApp extends StatefulWidget {
      @override
      _ExampleAppState createState() => new _ExampleAppState();
    }
    
    class _ExampleAppState extends State<ExampleApp> {
    
      Stereo _stereo;
    
      @override
      initState() {
        super.initState();
        _stereo = new Stereo();
        _playMusic();
      }
    
    
      _playMusic() async {
        await _copyFiles();
        await _loadMusic();
      }
    
      _loadMusic() async {
        String dir = '';
        String mp3 = "pi.mp3";
        await getApplicationDocumentsDirectory().then(
                (Directory directory) => dir = 'file://' + directory.path + '/');
        try {
          await _stereo.load('$dir$mp3');
    //      _stereo.play();
        } on StereoFileNotPlayableException {
          var alert = new AlertDialog(
              title: new Text('File not playable'),
              content: new Text('The file you specified is not playable.'));
          showDialog(context: context, child: alert);
        }
      }
    
      _copyFiles() async {
        final Directory dir = await getApplicationDocumentsDirectory();
    
        final File song = new File('${dir.path}/pi.mp3');
    
        if (!(await song.exists())) {
          final data = await rootBundle.load('assets/songs/pi.mp3');
          final bytes = data.buffer.asUint8List();
          await song.writeAsBytes(bytes, flush: true);
        }
      }
    
    
      @override
      Widget build(BuildContext context) {
        return Material(
          child: Scaffold(
            body: Container(),
          ),
        );
      }
    }
    

    Flutter --version

    Flutter 1.2.2 • channel dev • https://github.com/flutter/flutter.git
    Framework • revision 007a415c2a (9 weeks ago) • 2019-02-21 20:22:47 -0800
    Engine • revision f1f19bba8f
    Tools • Dart 2.2.0 (build 2.2.0-dev.2.1 c92d5ca288)
    
    opened by MarkOSullivan94 0
  • ios file picker does nothing

    ios file picker does nothing

    when i run the example and try to pick a file from my music on a real iPhone (emulator doesn't work AFAIK, since you can't put songs on the emulator) nothing happens.

    None of the songs get loaded into the player. In fact I can't even hit cancel to go back (edit 2: i can cancel if i hit it immediately, but if i try to select a song, then cancel, it hangs). Just stuck in the music file picker. so i have to manually close and restart the example (edit: apparently if i leave it long enough, it just crashes the app).

    error output in the xcode console (not sure if i can get a flutter error since I'm running it on a real device):

    https://pastebin.com/E44pCMFM

    opened by thejacer87 7
  • File Not Playable error

    File Not Playable error

    I'm testing the plugin on an Android device - tried to play the two given files (pi.mp3 and dubstep.mp3). but getting the StereoFileNotPlayableException. Tried reinstalling as per another issue but still the same error.

    For other files, getting a PlatformException(error, null, null) exception.

    Would appreciate some help getting around this. Thanks to @faku99 for working on a Flutter audio plugin - much needed!

    opened by suparnavg 1
  • Exception: Failed to handle method call

    Exception: Failed to handle method call

    I have tried to load the example and get this error:

    E/MediaPlayerNative(20252): stop called in state 1, mPlayer(0x0)
    E/MediaPlayerNative(20252): error (-38, 0)
    V/MediaPlayer(20252): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
    V/MediaPlayer(20252): cleanDrmObj: mDrmObj=null mDrmSessionId=null
    E/MethodChannel#com.twofind.stereo(20252): Failed to handle method call
    E/MethodChannel#com.twofind.stereo(20252): java.lang.IllegalArgumentException
    E/MethodChannel#com.twofind.stereo(20252): 	at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:74)
    E/MethodChannel#com.twofind.stereo(20252): 	at com.twofind.stereo.AudioTrack.toJson(AudioTrack.java:14)
    E/MethodChannel#com.twofind.stereo(20252): 	at com.twofind.stereo.StereoPlugin.load(StereoPlugin.java:155)
    E/MethodChannel#com.twofind.stereo(20252): 	at com.twofind.stereo.StereoPlugin.onMethodCall(StereoPlugin.java:75)
    E/MethodChannel#com.twofind.stereo(20252): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:191)
    E/MethodChannel#com.twofind.stereo(20252): 	at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:152)
    E/MethodChannel#com.twofind.stereo(20252): 	at android.os.MessageQueue.nativePollOnce(Native Method)
    E/MethodChannel#com.twofind.stereo(20252): 	at android.os.MessageQueue.next(MessageQueue.java:325)
    E/MethodChannel#com.twofind.stereo(20252): 	at android.os.Looper.loop(Looper.java:142)
    E/MethodChannel#com.twofind.stereo(20252): 	at android.app.ActivityThread.main(ActivityThread.java:6494)
    E/MethodChannel#com.twofind.stereo(20252): 	at java.lang.reflect.Method.invoke(Native Method)
    E/MethodChannel#com.twofind.stereo(20252): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    E/MethodChannel#com.twofind.stereo(20252): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
    W/MediaPlayer(20252): mediaplayer went away with unhandled events
    
    bug 
    opened by abacaj 8
Flutter apple music preview - A Music App that leverages the iTunes Rest API to get music data and playable music trailers

Apple Music Preview App Description This project is a Music App that leverages t

Willy Adinata Saragih 2 May 23, 2022
🎵 Elegant music app to play local music & YouTube music. Distributes music into albums & artists. Has playlists & lyrics.

Harmonoid Elegant music app to play local music & YouTube music. Download Now ?? Feel free to report bugs & issues. We'll be there to fix. Loving the

Harmonoid 2.5k Dec 30, 2022
Video player-2.2.10 - A Flutter plugin for iOS, Android and Web for playing back video on a Widget surface

Video Player plugin for Flutter A Flutter plugin for iOS, Android and Web for pl

null 2 Sep 29, 2022
Flutter Music Player - First Open Source Flutter based material design music player with audio plugin to play local music files.

Flutter Music Player First Open Source Flutter based Beautiful Material Design Music Player(Online Radio will be added soon.) Demo App Play Store BETA

Pawan Kumar 1.5k Jan 8, 2023
Playify is a Flutter plugin for play/pause/seek songs, fetching music metadata, and browsing music library.

Playify Playify is a Flutter plugin for play/pause/seek songs, fetching music metadata, and browsing music library. Playify was built using iOS's Medi

Ibrahim Berat Kaya 32 Dec 14, 2022
A simple app to keep track the time you Learn, Playing, Reading, ... in every week. This is also my attempt to teach myself Flutter & Dart

Progressor 0.0.1 Sometime you want to set a target for you weekly, for example: "Reading Book for 8 hours every week". This app helps you to do that.

Son Nguyen Hoang 4 Oct 12, 2022
Amazing Flutter package for playing audio with a lot of features to offer.

Flutter_exoplayer A Flutter plugin that let's you play multiple audio files simultaneously with an option to choose if to play in background or as a f

Daniel 48 Aug 7, 2022
Caffodils - Download everything | Flutter app for Android and IOS. Download Video, Reels, Shorts, Music, Images, Files from Instagram, Facebook and Youtube

caffodils Caffodils - Download everything Flutter app for Android and IOS. Download Video, Reels, Shorts, Music, Images, Files from Instagram, Faceboo

Caffodils 11 Oct 24, 2022
Music reader for online data (Google Drive implementation). Cross platform goal : iOS, Android, MacOS, Windows

omusic A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this i

JeanNicolasdeLamballerie 0 Nov 30, 2021
A Flutter plugin for music sequencing.

flutter_sequencer This Flutter plugin lets you set up sampler instruments and create multi-track sequences of notes that play on those instruments. Yo

Mike Perri 63 Dec 29, 2022
Audio manager - A flutter plugin for music playback, including notification handling.

audio_manager A flutter plugin for music playback, including notification handling. This plugin is developed for iOS based on AVPlayer, while android

Jerome Xiong 96 Oct 25, 2022
A Flutter plugin for handling Connectivity and REAL Connection state in the mobile, web and desktop platforms. Supports iOS, Android, Web, Windows, Linux and macOS.

cross_connectivity A Flutter plugin for handling Connectivity and REAL Connection state in the mobile, web and desktop platforms. Supports iOS, Androi

MarchDev Toolkit 29 Nov 15, 2022
A Flutter plugin to retrieve and manage contacts on Android and iOS devices. Maintainer: @lukasgit

contacts_service A Flutter plugin to access and manage the device's contacts. Usage To use this plugin, add contacts_service as a dependency in your p

Lukas Dickie 166 Dec 28, 2022
A Flutter plugin that supports Pangle SDK on Android and iOS.

Thanks for non-commercial open source development authorization by JetBrains. 穿山甲 Flutter SDK `pangle_flutter`是一款集成了字节跳动穿山甲 Android 和 iOS SDK的 Flutter

null 121 Dec 2, 2022
A robust Flutter plugin for making payments via Paystack Payment Gateway. Completely supports Android and iOS

?? Paystack Plugin for Flutter A Flutter plugin for making payments via Paystack Payment Gateway. Fully supports Android and iOS. ?? Installation To u

Wilberforce Uwadiegwu 165 Jan 4, 2023
A flutter plugin for integrating razorpay payment gateway. Supports Android and iOS.

Flutter Razorpay Plugin A flutter plugin for razorpay integration for both android and ios. If you use this library in your app, please let me know an

Chetan Kaushik 28 Dec 13, 2022
A flutter IM plugin for android and ios

flutter_openim_sdk Download demo flutter_openim_widget A flutter IM plugin for android and ios. Getting Started 1,Add dependency in yaml flutter_op

kostia7alania 1 Dec 3, 2021
A Flutter package for working with piano keys and sheet music

Piano A Flutter package that provides: logic for working with musical notes, clefs and octaves; a widget that can render notes on a clef; an interacti

Craig McMahon 32 Jan 5, 2023