audio_waveforms_fix

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

audio waveforms fix

Audio Waveforms #
Use this plugin to generate waveforms while recording audio in any file formats supported
by given encoders or from audio files. We can use gestures to scroll through the waveforms or seek to
any position while playing audio and also style waveforms.
Preview #

Recorder #
Platform specific configuration #
Android #
Change the minimum Android sdk version to 21 (or higher) in your android/app/build.gradle file.
minSdkVersion 21
copied to clipboard
Add RECORD_AUDIO permission in AndroidManifest.xml
<uses-permission android:name="android.permission.RECORD_AUDIO" />
copied to clipboard
IOS #
Add this two rows in ios/Runner/Info.plist
<key>NSMicrophoneUsageDescription</key>
<string>This app is requires Mic permission.</string>
copied to clipboard
This plugin requires ios 10.0 or higher. So add this line in Podfile
platform :ios, '10.0'
copied to clipboard
Installing #

Add dependency to pubspec.yaml

dependencies:
audio_waveforms: <latest-version>
copied to clipboard
Get the latest version in the 'Installing' tab on pub.dev

Import the package.

import 'package:audio_waveforms/audio_waveforms.dart';
copied to clipboard
Usage #

Initialise RecorderController

late final RecorderController recorderController;
@override
void initState() {
super.initState();
recorderController = RecorderController();
}
copied to clipboard

Use AudioWaveforms widget in widget tree

AudioWaveforms(
size: Size(MediaQuery.of(context).size.width, 200.0),
recorderController: recorderController,
),
copied to clipboard

Start recording (it will also display waveforms)

await recorderController.record();
copied to clipboard
You can provide file name with extension and full path in path parameter of record function. If
not provided .aac is the default extension and dateTime will be the file name.

Pause recording

await recorderController.pause();
copied to clipboard

Stop recording

final path = await recorderController.stop();
copied to clipboard
Calling this will save the recording at provided path and it will return path to that file.

Disposing RecorderController

@override
void dispose() {
recorderController.dispose();
super.dispose();
}
copied to clipboard
Additional feature #

Scroll through waveform

AudioWaveforms(
enableGesture: true,
),
copied to clipboard
By enabling gestures, you can scroll through waveform in recording state or paused state.

Refreshing the wave to initial position after scrolling

recorderController.refresh();
copied to clipboard
Once scrolled waveform will stop updating position with newly added waves while recording so we can
use this to get waves updating again. It can also be used in paused/stopped state.

Changing style of the waves

AudioWaveforms(
waveStyle: WaveStyle(
color: Colors.white,
showDurationLabel: true,
spacing: 8.0,
showBottom: false,
extendWaveform: true,
showMiddleLine: false,
),
),
copied to clipboard

Applying gradient to waves

AudioWaveforms(
waveStyle: WaveStyle(
gradient: ui.Gradient.linear(
const Offset(70, 50),
Offset(MediaQuery.of(context).size.width / 2, 0),
[Colors.red, Colors.green],
),
),
),
copied to clipboard

Show duration of the waveform

AudioWaveforms(
waveStyle: WaveStyle(showDurationLabel: true),
),
copied to clipboard

Change frequency of wave update and normalise according to need and platform

late final RecorderController recorderController;
@override
void initState() {
super.initState();
recorderController = RecorderController()
..updateFrequency = const Duration(milliseconds: 100)
..normalizationFactor = Platform.isAndroid ? 60 : 40;
}
copied to clipboard

Using different types of encoders and sample rate

late final RecorderController recorderController;
@override
void initState() {
super.initState();
recorderController = RecorderController()
..androidEncoder = AndroidEncoder.aac
..androidOutputFormat = AndroidOutputFormat.mpeg4
..iosEncoder = IosEncoder.kAudioFormatMPEG4AAC
..sampleRate = 16000;
}
copied to clipboard

Listening scrolled duration position

recorderController.currentScrolledDuration;
copied to clipboard
It is a ValueNotifier. You can listen to any changes in current scrolled duration by using this.
To use this shouldCalculateScrolledPosition flag needs to be enabled. Duration is in
milliseconds.
Player #
Usage #

Initialise PlayerController

late PlayerController playerController;
@override
void initState() {
super.initState();
playerController = PlayerController();
}
copied to clipboard

Prepare player

await playerController.preparePlayer(path);
copied to clipboard
Provide the audio file path in the parameter. You can also set volume with optional parameter.

Use AudioFileWaveforms in widget-tree

AudioFileWaveforms(
size: Size(MediaQuery.of(context).size.width, 100.0),
playerController: playerController,
)
copied to clipboard

Start player

await playerController.startPlayer();
copied to clipboard
As default when audio ends it will be seeked to start but you can pass false let it stay at end.

Pause player

await playerController.pausePlayer();
copied to clipboard

Stop player

await playerController.stopPlayer();
copied to clipboard

Disposing the playerController

@override
void dispose() {
playerController.dispose();
super.dispose();
}
copied to clipboard
Additional feature #

Set volume for the player

await playerController.setVolume(1.0);
copied to clipboard

Seek to any position

await playerController.seekTo(5000);
copied to clipboard

Get current/max duration of audio file

final duration = await playerController.getDuration(DurationType.max);
copied to clipboard

Seek using gestures

AudioFileWaveforms(
enableSeekGesture: true,
)
copied to clipboard
Audio also can be seeked using gestures on waveforms (enabled by default).

Ending audio with different modes

await playerController.startPlayer(finishMode: FinishMode.stop);
copied to clipboard
Using FinishMode.stop will stop the player, FinishMode.pause will pause the player at the end
and FinishMode.loop will loop the player.

Listening to player state changes

playerController.onPlayerStateChanged.listen((state) {});
copied to clipboard

Listening to current duration

playerController.onCurrentDurationChanged.listen((duration) {});
copied to clipboard
Duration is in milliseconds.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.