stereo 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

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 #


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:

1.0.2 #

  • Updates Gradle to 4.6 version.

1.0.1 #

  • Fixes a bug which would interfere with the audio_recorder library. Credits to joelfaul.

1.0.0 #

  • Initial release


import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;

import 'package:path_provider/path_provider.dart';
import 'package:stereo/stereo.dart';
import 'package:stereo_example/media_info_widget.dart';

import 'package:stereo_example/media_player_widget.dart';

void main() {
  runApp(new MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return new MaterialApp(
        title: 'Stereo Plugin Example', home: new HomeScreen());

class HomeScreen extends StatefulWidget {
  _HomeScreenState createState() => new _HomeScreenState();

class _HomeScreenState extends State<HomeScreen> {
  Stereo _stereo = new Stereo();

  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(title: new Text('Stereo Plugin Example')),
        body: new Column(children: <Widget>[
          new Center(
              heightFactor: 1.5,
              child: new Text('Choose an action:',
                  style: new TextStyle(
                      fontWeight: FontWeight.bold, fontSize: 20.0))),
          new Wrap(
              alignment: WrapAlignment.spaceAround,
              spacing: 12.0,
              runSpacing: 8.0,
              children: <Widget>[
                new RaisedButton(
                    child: new Text('Play dubstep.mp3'),
                    onPressed: () => _playFile('dubstep.mp3')),
                new RaisedButton(
                    child: new Text('Play pi.mp3'),
                    onPressed: () => _playFile('pi.mp3')),
                new RaisedButton(
                    child: new Text('Invalid URL'),
                    onPressed: () => _playFile("invalid_file.mp3")),
                new RaisedButton(
                    child: new Text('Pick file'), onPressed: () => _pickFile())
          new Container(height: 5.0),
          new MediaInfoWidget(),
          new Padding(
                  new EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0),
              child: new MediaPlayerWidget())

  Future _pickFile() async {
    try {
      AudioTrack track = await _stereo.picker();

      _playFile(track.path, false);
    } on StereoPermissionsDeniedException catch (_) {
      print('ERROR: Permissions denied');
    } on StereoNoTrackSelectedException {
      print('ERROR: No track selected');

  Future _playFile(String file, [bool fromAppDir = true]) async {
    String dir = '';

    if (fromAppDir) {
      await _copyFiles();

      await getApplicationDocumentsDirectory().then(
          (Directory directory) => dir = 'file://' + directory.path + '/');

    try {
      await _stereo.load('$dir$file');
    } 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);

  // Don't judge the code for this method, it's for the example...
  Future _copyFiles() async {
    final Directory dir = await getApplicationDocumentsDirectory();

    final File dubstepSong = new File('${dir.path}/dubstep.mp3');
    final File piSong = new File('${dir.path}/pi.mp3');

    if (!(await dubstepSong.exists())) {
      final data = await rootBundle.load('assets/songs/dubstep.mp3');
      final bytes = data.buffer.asUint8List();
      await dubstepSong.writeAsBytes(bytes, flush: true);
    if (!(await piSong.exists())) {
      final data = await rootBundle.load('assets/songs/pi.mp3');
      final bytes = data.buffer.asUint8List();
      await piSong.writeAsBytes(bytes, flush: true);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  stereo: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:stereo/stereo.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Maintenance suggestions

Package is getting outdated. (-30.96 points)

The package was last published 68 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies