Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter flutter logo sound 2-in-1

2-in-1 sound recorder & player. a flutter plugin for sound.

2-in-1 sound recorder & player
2-in-1 sound recorder & player

this plugin provides simple 2-in-1 recorder and player functionalities for both android and ios platforms. this only supports the 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).

2-in-1 sound recorder & player
2-in-1 sound recorder & player

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.
stoprecorder string messagestop recording.
startplayerstring uristring messagestart playing.
stopplayer string messagestop playing.
pauseplayer string messagepause playing.
resumeplayer string 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.
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

download the full project for this post from the following button

this source is fully free for all time

download as zip


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top
PUY NOW VIA WHATSAPP