ampos_flutter_sound 0.0.8+4

  • Readme
  • Changelog
  • Example
  • Installing
  • 70

ampos_flutter_sound #

Flutter Sound library that can record and play sound

fork from https://github.com/dooboolab/flutter_sound to enable save to cache storage in android

0.0.8+4 #

  • update ios example project

0.0.8+3 #

  • fix status mapper when null

0.0.8+2 #

  • fix player not working

0.0.8+1 #

  • remove v2 plugin

0.0.8 #

  • add passiveRetrieveStatus

0.0.7 #

  • change AmposFlutterSoundPlugin to java

0.0.6 #

  • fix iOS file path can't continue to use on flutter

0.0.5 #

  • Update base to 1.4.3.
  • Improve android sound quality.
  • Fix iOS not send audioPlayerDidFinishPlaying

0.0.4 #

  • Remove add null event when remove Stream Listeners.

0.0.3 #

  • Format Audio Recorder.

0.0.2 #

  • Fix package error.

0.0.1 #

  • First Released.

example/lib/main.dart

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

import 'package:ampos_flutter_sound/ampos_flutter_sound.dart';
import 'package:flutter/material.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart' show DateFormat;

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _isRecording = false;
  bool _isPlaying = false;
  bool _isReallyPlaying = false;

  StreamSubscription _recorderSubscription;
  StreamSubscription _dbPeakSubscription;
  StreamSubscription _playerSubscription;
  AmposFlutterSound flutterSound;

  String _recorderTxt = '00:00:00';
  String _playerTxt = '00:00:00';
  double _dbLevel;

  double sliderCurrentPosition = 0.0;
  double maxDuration = 1.0;

  String path = '';

  @override
  void initState() {
    super.initState();
    flutterSound = AmposFlutterSound(passiveRetrieveStatus: Platform.isAndroid);
    flutterSound.setSubscriptionDuration(0.01);
    flutterSound.setDbPeakLevelUpdate(0.8);
    flutterSound.setDbLevelEnabled(true);
    initializeDateFormatting();
  }

  Future<void> startRecorder() async {
    try {
      path = await flutterSound.startRecorder();
      print('startRecorder: $path');

      _recorderSubscription = flutterSound.onRecorderStateChanged.listen((e) {
        final DateTime date = DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt(), isUtc: true);
        final String txt = DateFormat('mm:ss:SS', 'en_GB').format(date);

        setState(() {
          _recorderTxt = txt.substring(0, 8);
        });
      });
      _dbPeakSubscription = flutterSound.onRecorderDbPeakChanged.listen((value) {
        print('got update -> $value');
        setState(() {
          _dbLevel = value;
        });
      });

      setState(() {
        _isRecording = true;
        _isReallyPlaying = true;
      });
    } catch (err) {
      print('startRecorder error: $err');
    }
  }

  Future<void> stopRecorder() async {
    try {
      final String result = await flutterSound.stopRecorder();
      print('stopRecorder: $result');

      if (_recorderSubscription != null) {
        _recorderSubscription.cancel();
        _recorderSubscription = null;
      }
      if (_dbPeakSubscription != null) {
        _dbPeakSubscription.cancel();
        _dbPeakSubscription = null;
      }

      setState(() {
        _isRecording = false;
        _isReallyPlaying = false;
      });
    } catch (err) {
      print('stopRecorder error: $err');
    }
  }

  Future<void> startPlayer() async {
    final String path = await flutterSound.startPlayer(this.path);
    await flutterSound.setVolume(1.0);
    print('startPlayer: $path');

    try {
      _playerSubscription = flutterSound.onPlayerStateChanged.listen((e) {
        if (e != null) {
          sliderCurrentPosition = e.currentPosition;
          maxDuration = e.duration;

          final DateTime date = DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt(), isUtc: true);
          final String txt = DateFormat('mm:ss:SS', 'en_GB').format(date);
          setState(() {
            _isPlaying = true;
            _isReallyPlaying = true;
            _playerTxt = txt.substring(0, 8);
          });
        }
      });
    } catch (err) {
      print('error: $err');
    }
  }

  Future<void> stopPlayer() async {
    try {
      final String result = await flutterSound.stopPlayer();
      print('stopPlayer: $result');
      if (_playerSubscription != null) {
        _playerSubscription.cancel();
        _playerSubscription = null;
      }

      setState(() {
        _isPlaying = false;
      });
    } catch (err) {
      print('error: $err');
    }
  }

  Future<void> pausePlayer() async {
    final String result = await flutterSound.pausePlayer();
    setState(() {
      _isPlaying = false;
    });
    print('pausePlayer: $result');
  }

  Future<void> resumePlayer() async {
    final String result = await flutterSound.resumePlayer();
    setState(() {
      _isPlaying = true;
    });
    print('resumePlayer: $result');
  }

  Future<void> seekToPlayer(int milliSecs) async {
    final String result = await flutterSound.seekToPlayer(milliSecs);
    print('seekToPlayer: $result');
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Sound'),
        ),
        body: ListView(
          children: <Widget>[
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  margin: EdgeInsets.only(top: 24.0, bottom: 16.0),
                  child: Text(
                    _recorderTxt,
                    style: TextStyle(
                      fontSize: 48.0,
                      color: Colors.black,
                    ),
                  ),
                ),
                _isRecording
                    ? LinearProgressIndicator(
                        value: 100.0 / 160.0 * (_dbLevel ?? 1) / 100,
                        valueColor: AlwaysStoppedAnimation<Color>(Colors.green),
                        backgroundColor: Colors.red,
                      )
                    : Container()
              ],
            ),
            Row(
              children: <Widget>[
                Container(
                  width: 56.0,
                  height: 56.0,
                  child: ClipOval(
                    child: FlatButton(
                      onPressed: () {
                        if (!_isRecording) {
                          return startRecorder();
                        }
                        return stopRecorder();
                      },
                      padding: EdgeInsets.all(8.0),
                      child: Image(
                        image: _isRecording ? AssetImage('res/icons/ic_stop.png') : AssetImage('res/icons/ic_mic.png'),
                      ),
                    ),
                  ),
                ),
              ],
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  margin: EdgeInsets.only(top: 60.0, bottom: 16.0),
                  child: Text(
                    _playerTxt,
                    style: TextStyle(
                      fontSize: 48.0,
                      color: Colors.black,
                    ),
                  ),
                ),
              ],
            ),
            Row(
              children: <Widget>[
                Container(
                  width: 56.0,
                  height: 56.0,
                  child: ClipOval(
                    child: FlatButton(
                      onPressed: () {
                        if (_isReallyPlaying) {
                          resumePlayer();
                        } else {
                          startPlayer();
                        }
                      },
                      padding: EdgeInsets.all(8.0),
                      child: Image(
                        image: AssetImage('res/icons/ic_play.png'),
                      ),
                    ),
                  ),
                ),
                Container(
                  width: 56.0,
                  height: 56.0,
                  child: ClipOval(
                    child: FlatButton(
                      onPressed: () {
                        pausePlayer();
                      },
                      padding: EdgeInsets.all(8.0),
                      child: Image(
                        width: 36.0,
                        height: 36.0,
                        image: AssetImage('res/icons/ic_pause.png'),
                      ),
                    ),
                  ),
                ),
                Container(
                  width: 56.0,
                  height: 56.0,
                  child: ClipOval(
                    child: FlatButton(
                      onPressed: () {
                        stopPlayer();
                      },
                      padding: EdgeInsets.all(8.0),
                      child: Image(
                        width: 28.0,
                        height: 28.0,
                        image: AssetImage('res/icons/ic_stop.png'),
                      ),
                    ),
                  ),
                ),
              ],
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
            ),
            Container(
                height: 56.0,
                child: Slider(
                    value: sliderCurrentPosition,
                    min: 0.0,
                    max: maxDuration,
                    onChanged: (double value) async {
                      await flutterSound.seekToPlayer(value.toInt());
                    },
                    divisions: maxDuration.toInt()))
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  ampos_flutter_sound: ^0.0.8+4

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

We analyzed this package on Jul 2, 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:ampos_flutter_sound/ampos_flutter_sound.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:ampos_flutter_sound/ampos_flutter_sound.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:ampos_flutter_sound/ampos_flutter_sound.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:ampos_flutter_sound/ampos_flutter_sound.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

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

Health suggestions

Format lib/ampos_flutter_sound.dart.

Run flutter format to format lib/ampos_flutter_sound.dart.

Format lib/model/exceptions.dart.

Run flutter format to format lib/model/exceptions.dart.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://bitbucket.org/ampos/ampos_flutter_sound was unreachable.

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.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8