audio 0.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 86

Multi-player audio #

This plugin is under development, this already being used in production. Just make sure you understand what's missing

Example running on Android

Flutter Audio which will both play and record audio (upcoming feature).

(after failed tries trying to work and combine few existing plugins, due the continues issues I had I decided to create this plugin)

The aim of this plugin is really to give a solid solution for audio, feel free to open issues with new requests or pull requests. This is extremely important to have such a plugin that is very activate with updates.

And of course, performance. Even thought this package is offering lots of features. I really care about the performance, so I took a close care of it.

Features #

  • Audio player with support to multiple players simultaneously
  • Buffer updates on the player (percent of the loading whether it's local or remote file)
  • Preload the audio
  • Audio Recorder (upcoming feature)

I'll be adding soon more support, my goal is to make this plugin a complete solution.

0.0.5 #

  • Updated Uuid version to latest

0.0.4 #

  • Fixed gif

0.0.3 #

  • Added gif

0.0.2 #

  • Added LICENSE
  • Added example snippet

0.0.1 #

  • Multiplayer audio support

example/README.md

audio_example #


@immutable
class AudioPlayerDemo extends StatefulWidget
{
    final String url;

    AudioPlayerDemo(this.url);

    @override
    State<StatefulWidget> createState() => AudioPlayerDemoState();
}

class AudioPlayerDemoState extends State<AudioPlayerDemo>
{
    Audio audioPlayer = new Audio(single: true);
    AudioPlayerState state = AudioPlayerState.STOPPED;
    double position = 0;
    StreamSubscription<AudioPlayerState> _playerStateSubscription;
    StreamSubscription<double> _playerPositionController;
    StreamSubscription<int> _playerBufferingSubscription;
    StreamSubscription<AudioPlayerError> _playerErrorSubscription;

    @override
    void initState()
    {
        _playerStateSubscription = audioPlayer.onPlayerStateChanged.listen((AudioPlayerState state)
        {
            print("onPlayerStateChanged: ${audioPlayer.uid} $state");

            if (mounted)
                setState(() => this.state = state);
        });

        _playerPositionController = audioPlayer.onPlayerPositionChanged.listen((double position)
        {
            print("onPlayerPositionChanged: ${audioPlayer.uid} $position ${audioPlayer.duration}");

            if (mounted)
                setState(() => this.position = position);
        });

        _playerBufferingSubscription = audioPlayer.onPlayerBufferingChanged.listen((int percent)
        {
            print("onPlayerBufferingChanged: ${audioPlayer.uid} $percent");
        });

        _playerErrorSubscription = audioPlayer.onPlayerError.listen((AudioPlayerError error)
        {
            throw("onPlayerError: ${error.code} ${error.message}");
        });

        audioPlayer.preload(widget.url);

        super.initState();
    }

    @override
    Widget build(BuildContext context)
    {
        Widget status = Container();

        print("[build] uid=${audioPlayer.uid} duration=${audioPlayer.duration} state=$state");

        switch (state)
        {
            case AudioPlayerState.LOADING:
            {
                status = Container(
                    padding: const EdgeInsets.all(12.0),
                    child: Container(
                        child: Center(
                            child: CircularProgressIndicator(strokeWidth: 2.0)),
                        width: 24.0,
                        height: 24.0
                    )
                );
                break;
            }

            case AudioPlayerState.PLAYING:
            {
                status = IconButton(icon: Icon(Icons.pause, size: 28.0), onPressed: onPause);
                break;
            }

            case AudioPlayerState.READY:
            case AudioPlayerState.PAUSED:
            case AudioPlayerState.STOPPED:
            {
                status = IconButton(icon: Icon(Icons.play_arrow, size: 28.0), onPressed: onPlay);

                if (state == AudioPlayerState.STOPPED)
                    audioPlayer.seek(0.0);

                break;
            }
        }

        return Container(
            padding: const EdgeInsets.symmetric(vertical: 32.0, horizontal: 16.0),
            child: Column(
                children: <Widget>[
                    Text(audioPlayer.uid),
                    Row(
                        children: <Widget>[
                            status,
                            Slider(
                                max: audioPlayer.duration.toDouble(),
                                value: position.toDouble(),
                                onChanged: onSeek,
                            ),
                            Text("${audioPlayer.duration.toDouble()}ms")
                        ],
                    )
                ],
            ),
        );
    }

    @override
    void dispose()
    {
        _playerStateSubscription.cancel();
        _playerPositionController.cancel();
        _playerBufferingSubscription.cancel();
        _playerErrorSubscription.cancel();
        audioPlayer.release();
        super.dispose();
    }

    onPlay()
    {
        audioPlayer.play(widget.url);
    }

    onPause()
    {
        audioPlayer.pause();
    }

    onSeek(double value)
    {
        // Note: We can only seek if the audio is ready
        audioPlayer.seek(value);
    }
}

Use this package as a library

1. Depend on it

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


dependencies:
  audio: ^0.0.5

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

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

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/audio.dart.

Run flutter format to format lib/audio.dart.

Maintenance suggestions

The package description is too short. (-16 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
uuid ^2.0.1 2.0.2
Transitive dependencies
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8