audio_widget 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

audio_widget #

sample

(this widget does not display anything)

Play an audio on flutter can be as simple as display an image ! Just add a widget into the tree

Audio.assets(
  path: "assets/audios/country.mp3",
  play: true, //AudioWidget does not maintain the play state
  child: ...
)

⏯ Play / Pause #

Like usual Flutter widgets, just update the parameters of the Audio

//inside a stateful widget

bool _play = false;

@override
Widget build(BuildContext context) {
  return Audio.assets(
     path: "assets/audios/country.mp3",
     play: _play,
     child: RaisedButton(
       child: Text(
         _play ? "pause" : "play",
       ),
       onPressed: () {
         setState(() {
           _play = !_play;
         });
       },
     ),
  );
}

🛑 How to stop ? #

Just remove the Audio from the tree ! Or simply keep play: false

⏩ How to seek ? #

Just update the initialPosition of the Audio

//inside a stateful widget

Duration _seek;

@override
Widget build(BuildContext context) {
  return Audio.assets(
     path: "assets/audios/country.mp3",
     play: true,
     initialPosition: _seek,
     child: RaisedButton(
       child: Text("seek"),
       onPressed: () {
         setState(() {
           _seek = Duration(seconds: 30);
         });
       },
     ),
  );
}

🙉 Listeners #

Audio.assets(
  path: "assets/audios/country.mp3",
  play: _play,

  onReadyToPlay: (duration) {
     //onReadyToPlay
  },
  
  onPositionChanged: (current, duration) {
     //onReadyToPlay
  },

  child: ...
)

💽 Player #

By default, Audio uses Assets Audio Player to play its songs

You can change it just by create a new wrapper of AudioWidgetPlayer

class AudioWidgetMyPlayer extends AudioWidgetPlayer {
  final MyPlayer _player = MyPlayer();

  @override
  void play() => _player.play();

  @override
  void pause() => _player.pause();

  //etc.

and update the defaultAudioWidgetPlayer inside your main

void main() {
    defaultAudioWidgetPlayer = () => AudioWidgetMyPlayer();
    runApp(MyApp());
}

[1.0.0] #

  • Initial import

example/lib/main.dart

import 'package:audio_widget/audio_widget.dart';
import 'package:flutter/material.dart';

import './string_duration.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("sample"),
      ),
      body: SizedBox.expand(child: MyPageWithAudio()),
    );
  }
}

class MyPageWithAudio extends StatefulWidget {
  @override
  _MyPageWithAudioState createState() => _MyPageWithAudioState();
}

class _MyPageWithAudioState extends State<MyPageWithAudio> {
  bool _play = false;
  String _currentPosition = "";

  @override
  Widget build(BuildContext context) {
    return Audio.assets(
      path: "assets/audios/country.mp3",
      play: _play,
      onReadyToPlay: (total) {
        setState(() {
          _currentPosition = "${Duration().mmSSFormat} / ${total.mmSSFormat}";
        });
      },
      onPositionChanged: (current, total) {
        setState(() {
          _currentPosition = "${current.mmSSFormat} / ${total.mmSSFormat}";
        });
      },
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        children: <Widget>[
          Text("Country music"),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: RaisedButton(
              shape: CircleBorder(),
              padding: EdgeInsets.all(14),
              color: Theme.of(context).primaryColor,
              child: Icon(
                _play ? Icons.pause : Icons.play_arrow,
                color: Colors.white,
              ),
              onPressed: () {
                setState(() {
                  _play = !_play;
                });
              },
            ),
          ),
          Text(_currentPosition),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  audio_widget: ^1.0.0

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

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:audio_widget/audio_widget.dart, package:audio_widget/src/player/defaultAudioPlayer.dart, package:audio_widget/src/player/audio_widget_player_assetsaudioplayer.dart, package:assets_audio_player/assets_audio_player.dart] that declares support for platforms: android, ios, macos

Package does not support Flutter platform web

Because of import path [package:audio_widget/audio_widget.dart, package:audio_widget/src/player/defaultAudioPlayer.dart, package:audio_widget/src/player/audio_widget_player_assetsaudioplayer.dart, package:assets_audio_player/assets_audio_player.dart] that declares support for platforms: android, ios, macos

Package does not support Flutter platform windows

Because of import path [package:audio_widget/audio_widget.dart, package:audio_widget/src/player/defaultAudioPlayer.dart, package:audio_widget/src/player/audio_widget_player_assetsaudioplayer.dart, package:assets_audio_player/assets_audio_player.dart] that declares support for platforms: android, ios, macos

Package not compatible with SDK dart

because of import path [audio_widget] that is in a package requiring null.

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 (assets_audio_player).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
assets_audio_player ^1.4.0 1.7.0 2.0.7+9
flutter 0.0.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
crypto 2.1.5
meta 1.1.8 1.2.1
rxdart 0.24.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
uuid 2.2.0
vector_math 2.0.8
Dev dependencies
flutter_test