stereo 1.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 84

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:

1.0.1

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

1.0.0

  • Initial release

example/lib/main.dart

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 {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        title: 'Stereo Plugin Example', home: new HomeScreen());
  }
}

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

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

  @override
  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(
              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:


dependencies:
  stereo: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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';
  
Version Uploaded Documentation Archive
1.0.1 Jun 7, 2018 Go to the documentation of stereo 1.0.1 Download stereo 1.0.1 archive
1.0.0 Mar 20, 2018 Go to the documentation of stereo 1.0.0 Download stereo 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
69
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

We analyzed this package on Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8
  • Flutter: 0.5.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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.6 1.14.11
meta 1.1.5 1.1.6
sky_engine 0.0.99
typed_data 1.1.5 1.1.6
vector_math 2.0.6 2.0.8
Dev dependencies
flutter_test