Skip to content

Commit

Permalink
✨ play multiple audio files
Browse files Browse the repository at this point in the history
  • Loading branch information
ujas-m-simformsolutions committed Apr 27, 2022
1 parent 4990b36 commit 73441af
Show file tree
Hide file tree
Showing 30 changed files with 1,001 additions and 782 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## [0.1.0] - 12 April, 2022 [Unreleased]
## [0.1.0] - 26 April, 2022 [Unreleased]

* Added functionality to play audio file and generate waveform from it.
* Breaking: Renamed WaveController to RecorderController
* Updated metering level for ios to average power
* Fixed label would not clear after stopping the recorder. With this, exposed `reset()` function to remove labels
when `callReset` flag in `stop()` is set to false.
* Updated example app


## [0.0.4] - 23 April, 2022 [Unreleased]
## [0.0.4] - 11 April, 2022 [Unreleased]

* Separated encoder input for android and ios better support

Expand Down
77 changes: 26 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Audio Waveforms

Use this plugin to generate waveforms while recording audio in any file formats supported
by given encoders. We can use gestures to scroll through the waveforms and also style waveforms.
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.


### Recorder
Expand Down Expand Up @@ -55,43 +56,43 @@ import 'package:audio_waveforms/audio_waveforms.dart';

1. Initialise WaveController
```dart
late final WaveController waveController;
late final RecorderController recorderController;
@override
void initState() {
super.initState();
waveController = WaveController();
recorderController = RecorderController();
}
```
2. Use `AudioWaveforms` widget in widget tree
```dart
AudioWaveforms(
size: Size(MediaQuery.of(context).size.width, 200.0),
waveController: waveController,
recorderController: recorderController,
),
```
3. Start recording (it will also display waveforms)
```dart
await waveController.record();
await recorderController.record();
```
You can provide file name with extension and full path in path parameter of record function. If
not provided .aac is default extension and dateTime will be file name.

4. Pause recording
```dart
await waveController.pause();
await recorderController.pause();
```
5. Stop recording
```dart
final path = await waveController.stop();
final path = await recorderController.stop();
```
Calling this will save the recording at provided path and it will return path to that file.

6. Disposing WaveController
```dart
@override
void dispose() {
waveController.disposeFunc();
recorderController.disposeFunc();
super.dispose();
}
```
Expand All @@ -107,32 +108,12 @@ By enabling gestures, you can scroll through waveform in recording state or paus

2. Refreshing the wave to initial position after scrolling
```dart
waveController.refresh();
recorderController.refresh();
```
Once scrolled waveform will stop updating position with newly added wave while recording so we can
use this to get waves updating again. It can also be used in paused/stopped state.

3. Changing background of the Waveform
```dart
AudioWaveforms(
size: Size(MediaQuery.of(context).size.width, 200.0),
waveController: waveController,
margin: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14.0),
gradient: const LinearGradient(
colors: <Color>[
Color(0xFF615766),
Color(0xFF394253),
Color(0xFF412B4F),
],
begin: Alignment.bottomLeft,
stops: <double>[0.2, 0.45, 0.8],
),
),
),
```
4. Changing style of the waves
3. Changing style of the waves
```dart
AudioWaveforms(
waveStyle: WaveStyle(
Expand All @@ -145,7 +126,7 @@ AudioWaveforms(
),
),
```
5. Applying gradient to waves
4. Applying gradient to waves
```dart
AudioWaveforms(
waveStyle: WaveStyle(
Expand All @@ -157,34 +138,33 @@ AudioWaveforms(
),
),
```

6. Show duration of the waveform
5. Show duration of the waveform
```dart
AudioWaveforms(
waveStyle: WaveStyle(showDurationLabel: true),
),
```
7. Change frequency of wave update and normalise according to need and platform
6. Change frequency of wave update and normalise according to need and platform
```dart
late final WaveController waveController;
late final RecorderController recorderController;
@override
void initState() {
super.initState();
waveController = WaveController()
recorderController = RecorderController()
..updateFrequency = const Duration(milliseconds: 100)
..normalizationFactor = Platform.isAndroid ? 60 : 40;
}
```
8. Using different types of encoders and sample rate
7. Using different types of encoders and sample rate
```dart
late final WaveController waveController;
late final RecorderController waveController;
@override
void initState() {
super.initState();
waveController = WaveController()
..encoder = Encoder.aac
recorderController = RecorderController()
..androidEncoder = AndroidEncoder.aac
..androidOutputFormat = AndroidOutputFormat.mpeg4
..iosEncoder = IosEncoder.kAudioFormatMPEG4AAC
..sampleRate = 16000;
}
```
Expand All @@ -195,7 +175,6 @@ late final WaveController waveController;
1. Initialise PlayerController
```dart
late PlayerController playerController;
@override
void initState() {
super.initState();
Expand Down Expand Up @@ -223,15 +202,11 @@ As default when audio ends it will be seeked to start but you can pass false let
```dart
await playerController.pausePlayer();
```
6. Resume player
```dart
await playerController.resumePlayer();
```
7. Stop player
6. Stop player
```dart
await playerController.stopPlayer();
```
8. Disposing the playerController
7. Disposing the playerController
```dart
@override
void dispose() {
Expand All @@ -247,11 +222,11 @@ await playerController.setVolume(1.0);
```
2. Seek to any position
```dart
playerController.seekTo(5000);
await playerController.seekTo(5000);
```
3. Get current/max duration of audio file
```dart
final duration = await playerController.getDuration();
final duration = await playerController.getDuration(DurationType.max);
```
4. Seek using gestures
```dart
Expand Down
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation("androidx.multidex:multidex:2.0.1")
implementation "com.google.android.exoplayer:exoplayer:2.17.1"
}
Loading

0 comments on commit 73441af

Please sign in to comment.