md_media_controls 0.0.79

  • Readme
  • Changelog
  • Example
  • Installing
  • 70

md_media_controls #

A new flutter plugin project.

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

MdMediaControls #

A Flutter audio plugin (Swift/Kotlin) to play remote or local audio files and control it on LockScreen(iOS only, Android part will be ready soon)

Features #

  • [x] Android & iOS
    • [x] play (remote file)
    • [x] stop
    • [x] pause
    • [x] onEnd
    • [x] position/duration
    • [x] seek
    • [x] mute
    • [x] rate / onChangeRate
  • [x] iOS
    • [x] lockScreen controls
    • [x] lockScreen events
  • [x] Android
    • TBD

Usage #

Example

To use this plugin :

  dependencies:
    flutter:
      sdk: flutter
    md_media_controls:
  • Instantiate an MdMediaControls instance
//...
MdMediaControls mdMediaControls = new MdMediaControls();
//...

Player Controls #


const testUrl = "https://raw.githubusercontent.com/IgorBaranov/md_media_controls/master/example.mp3";

StreamBuilder<ControlsState>(
              initialData: ControlsState.STOPPED,
              stream: mdMediaControls.onPlayerStateChanged,
              builder: (BuildContext context, AsyncSnapshot<ControlsState> snapshot) {
                final ControlsState data = snapshot.data;

                return Row(mainAxisSize: MainAxisSize.min, children: [
                  IconButton(
                      onPressed: data == ControlsState.PLAYING ? null : () async {
                        await mdMediaControls.playNew(url: testUrl, rate: 2.0);
                        await mdMediaControls.setInfo(title: 'Some title', artist: 'some artist',
                            imageUrl: 'https://pngimage.net/wp-content/uploads/2018/05/example-icon-png-4.png'
                        );
                      },
                      iconSize: 64.0,
                      icon: Icon(Icons.play_arrow),
                      color: Colors.cyan),
                  IconButton(
                      onPressed: data == ControlsState.PLAYING ? () {
                        mdMediaControls.pause();
                      } : null,
                      iconSize: 64.0,
                      icon: Icon(Icons.pause),
                      color: Colors.cyan),
                  IconButton(
                      onPressed: data == ControlsState.PLAYING || data == ControlsState.PAUSED ? () {
                        mdMediaControls.stop();
                      } : null,
                      iconSize: 64.0,
                      icon: Icon(Icons.stop),
                      color: Colors.amberAccent),
                  IconButton(
                      onPressed: () async {
                        await mdMediaControls.setInfo(title: 'Some title 123', artist: 'some artist 123',
                            imageUrl: 'assets/test.png'
                        );
                      },
                      iconSize: 64.0,
                      icon: Icon(Icons.adb),
                      color: Colors.amberAccent),

                ]);
              },
            )

Status current position, seek and rate #

The dart part of the plugin listen for platform calls :

StreamBuilder<ControlsState>(
                    initialData: ControlsState.STOPPED,
                    stream: mdMediaControls.onPlayerStateChanged,
                    builder: (BuildContext context, AsyncSnapshot<ControlsState> snapshot) {
                      final ControlsState data = snapshot.data;

                      return Row(mainAxisSize: MainAxisSize.min, children: [
                        IconButton(
                            onPressed: data == ControlsState.PLAYING ? null : () async {
                              await mdMediaControls.playNew(url: 'another url', rate: 1.0);
                              await mdMediaControls.setInfo(title: 'Some title', artist: 'some artist',
                                  imageUrl: 'https://pngimage.net/wp-content/uploads/2018/05/example-icon-png-4.png'
                              );
                            },
                            iconSize: 64.0,
                            icon: Icon(Icons.play_arrow),
                            color: Colors.cyan),
                        IconButton(
                            onPressed: data == ControlsState.PLAYING ? () {
                              mdMediaControls.pause();
                            } : null,
                            iconSize: 64.0,
                            icon: Icon(Icons.pause),
                            color: Colors.cyan),
                        IconButton(
                            onPressed: data == ControlsState.PLAYING || data == ControlsState.PAUSED ? () {
                              mdMediaControls.stop();
                            } : null,
                            iconSize: 64.0,
                            icon: Icon(Icons.stop),
                            color: Colors.amberAccent),

                      ]);
                    },
                  ),
                  StreamBuilder<Duration>(
                      initialData: Duration(),
                      stream: mdMediaControls.positionChanged,
                      builder: (BuildContext context, AsyncSnapshot<Duration> snapshot) {
                        final double max = sound.service.duration.inSeconds.toDouble();
                        final double value = snapshot.data.inSeconds.toDouble();

                        return Column(
                          children: <Widget>[
                            max > 0.0 ? Center(
                                child: Text('$value/$max')
                            ) : Container(),
                            value >= 0.0 && value <= max ? Slider(
                                onChanged: (double seconds) {
                                  mdMediaControls.seek(seconds);
                                },
                                min: 0.0,
                                value: value,
                                max: max
                            ) : Slider(
                                onChanged: null,
                                min: 0.0,
                                value: 0.0,
                                max: max
                            )
                          ],
                        );
                      }
                  ),
                  StreamBuilder<double>(
                    initialData: 1.0,
                    stream: mdMediaControls.onRateChanged,
                    builder: (BuildContext context, AsyncSnapshot<double> snapshot) {
                      return Column(
                        children: <Widget>[
                          Text('${snapshot.data}'),
                          Container(
                              child: Center(
                                child: Slider(
                                    onChanged: (double rate) => mdMediaControls.rate(rate: rate),
                                    value: snapshot.data,
                                    min: 0.0,
                                    max: 5.0
                                ),
                              )
                          )
                        ],
                      );
                    }
                  )

Do not forget to cancel all the subscriptions when the widget is disposed.

iOS #

⚠️ iOS App Transport Security #

By default iOS forbids loading from non-https url. To cancel this restriction edit your .plist and add :

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Getting Started #

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

0.0.29 #

refactoring, sry guys I'll add docs soon)

example/README.md

md_media_controls_example #

Demonstrates how to use the md_media_controls plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  md_media_controls: ^0.0.79

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:md_media_controls/md_media_controls.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
57
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Nov 19, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

31 out of 31 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/md_media_controls.dart.

Run flutter format to format lib/md_media_controls.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (path_provider).

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
meta ^1.1.6 1.1.7 1.1.8
path_provider ^0.5.0+1 0.5.0+1 1.4.2
Transitive dependencies
collection 1.14.11 1.14.12
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8