flutter_sound 1.1.5

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

flutter_sound

pub version

This plugin provides simple recorder and player functionalities for both `android` and `ios` platforms. This only supports default file extension for each platform. This plugin handles file from remote url. This plugin can handle playback stream from native (To sync exact time with bridging).

Free Read

Medium Blog

Getting Started

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

Install

Add flutter_sound as a dependency in pubspec.yaml For help on adding as a dependency, view the documentation.

Post Installation

On iOS you need to add a usage description to info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>This sample uses the microphone to record your speech and convert it to text.</string>
<key>UIBackgroundModes</key>
<array>
	<string>audio</string>
</array>

On Android you need to add a permission to AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Methods

FuncParamReturnDescription
setSubscriptionDurationdouble secString messageSet subscription timer in seconds. Default is 0.01 if not using this method.
startRecorderString uriString uriStart recording. This will return uri used.
stopRecorderString messageStop recording.
startPlayerString uriString messageStart playing.
stopPlayerString messageStop playing.
pausePlayerString messagePause playing.
resumePlayerString messageResume playing.
seekToPlayerint milliSecs position to goToString messageSeek audio to selected position in seconds. Parameter should be less than audio duration to correctly placed.

Subscriptions

SubscriptionReturnDescription
onRecorderStateChanged<RecordStatus>Able to listen to subscription when recorder starts.
onPlayerStateChanged<PlayStatus>Able to listen to subscription when player starts.

Default uri path

When uri path is not set during the function call in startRecorder or startPlayer, they are saved in below path depending on the platform.

  • Default path for android
    • sdcard/sound.mp4.
  • Default path for ios
    • sound.m4a.

Usage

Creating instance.

FlutterSound flutterSound = new FlutterSound();

Starting recorder with listener.

String path = await flutterSound.startPlayer(null);
print('startPlayer: $path');
_playerSubscription = flutterSound.onPlayerStateChanged.listen((e) {
	if (e != null) {
		DateTime date = new DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
		String txt = DateFormat('mm:ss:SS', 'en_US').format(date);
		this.setState(() {
			this._isPlaying = true;
			this._playerTxt = txt.substring(0, 8);
		});
	}
});

Stop recorder

String result = await flutterSound.stopRecorder();
print('stopRecorder: $result');

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

Start player

String path = await flutterSound.startPlayer(null);
print('startPlayer: $path');

_playerSubscription = flutterSound.onPlayerStateChanged.listen((e) {
	if (e != null) {
		DateTime date = new DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
		String txt = DateFormat('mm:ss:SS', 'en_US').format(date);
		this.setState(() {
			this._isPlaying = true;
			this._playerTxt = txt.substring(0, 8);
		});
	}
});

Stop player

String result = await flutterSound.stopPlayer();
print('stopPlayer: $result');
if (_playerSubscription != null) {
	_playerSubscription.cancel();
	_playerSubscription = null;
}

Pause player

String result = await flutterSound.pausePlayer();

Resume player

String result = await flutterSound.resumePlayer();

Seek player

String result = await flutterSound.seekToPlayer(miliSecs);

Setting subscription duration (Optional). 0.01 is default value when not set.

/// 0.01 is default
flutterSound.setSubscriptionDuration(0.01);

Setting volume.

/// 1.0 is default
/// Currently, volume can be changed when player is running. Try manage this right after player starts.
String path = await flutterSound.startPlayer(null);
await flutterSound.setVolume(0.1);

TODO

  • [ ] Seeking example in Exmaple project
  • [x] Volume Control
  • [x] Sync timing for recorder callback handler

Help Maintenance

I've been maintaining quite many repos these days and burning out slowly. If you could help me cheer up, buying me a cup of coffee will make my life really happy and get much energy out of it. <br/><a href="https://www.buymeacoffee.com/dooboolab" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/purple_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>

1.1.+

  • Released 1.1.0 with beautiful logo from mansa.
  • Improved readme.
  • Resolve #7.

1.0.9

  • Reimport intl which is needed to format date in Dart.

1.0.8

  • Implemented setVolume method.
  • Specific error messages given in android.
  • Manage ios player thread when audio is not loaded.

1.0.7

  • Safer handling of progressUpdate in ios when audio is invalid.

1.0.6

  • Fixed bug in platform specific code.

1.0.5

  • Fixed pug in seekToPlayer in ios.

1.0.3

  • Added license.

1.0.0

  • Released preview version for audio recorder and player.

example/README.md

flutter_sound_example

This is not a playlist audio module and this library provides simple recorder and player functionalities for both android and ios platforms. This only supports default file extension for each platform. This module can also handle file from url.

Getting Started

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

Install

Add flutter_sound as a dependency in pubspec.yaml For help on adding as a dependency, view the documentation.

Post Installation

On iOS you need to add a usage description to info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>This sample uses the microphone to record your speech and convert it to text.</string>
<key>UIBackgroundModes</key>
<array>
	<string>audio</string>
</array>

On Android you need to add a permission to AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO" />

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_sound: ^1.1.5

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:flutter_sound/flutter_sound.dart';
  
Version Uploaded Documentation Archive
1.1.5 Oct 29, 2018 Go to the documentation of flutter_sound 1.1.5 Download flutter_sound 1.1.5 archive
1.1.4 Oct 24, 2018 Go to the documentation of flutter_sound 1.1.4 Download flutter_sound 1.1.4 archive
1.1.3 Oct 10, 2018 Go to the documentation of flutter_sound 1.1.3 Download flutter_sound 1.1.3 archive
1.1.1 Aug 29, 2018 Go to the documentation of flutter_sound 1.1.1 Download flutter_sound 1.1.1 archive
1.1.0 Aug 29, 2018 Go to the documentation of flutter_sound 1.1.0 Download flutter_sound 1.1.0 archive
1.0.9 Aug 29, 2018 Go to the documentation of flutter_sound 1.0.9 Download flutter_sound 1.0.9 archive
1.0.8 Aug 29, 2018 Go to the documentation of flutter_sound 1.0.8 Download flutter_sound 1.0.8 archive
1.0.7 Aug 29, 2018 Go to the documentation of flutter_sound 1.0.7 Download flutter_sound 1.0.7 archive
1.0.6 Aug 20, 2018 Go to the documentation of flutter_sound 1.0.6 Download flutter_sound 1.0.6 archive
1.0.5 Aug 20, 2018 Go to the documentation of flutter_sound 1.0.5 Download flutter_sound 1.0.5 archive

All 16 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
85
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]
93
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8