Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "3.22.2"
}
29 changes: 13 additions & 16 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void main() {
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -23,7 +23,7 @@ class MyApp extends StatelessWidget {
}

class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
const Home({super.key});

@override
State<Home> createState() => _HomeState();
Expand All @@ -32,7 +32,7 @@ class Home extends StatefulWidget {
class _HomeState extends State<Home> {
late Duration maxDuration;
late Duration elapsedDuration;
late AudioCache audioPlayer;
late AudioPlayer audioPlayer;
late List<double> samples;
late int totalSamples;

Expand Down Expand Up @@ -60,15 +60,14 @@ class _HomeState extends State<Home> {
"totalSamples": totalSamples,
};
final samplesData = await compute(loadparseJson, audioDataMap);
await audioPlayer.load(audioData[1]);
await audioPlayer.play(audioData[1]);
await audioPlayer.audioCache.load(audioData[1]);
// await audioPlayer.audioCache(audioData[1]);
// maxDuration in milliseconds
await Future.delayed(const Duration(milliseconds: 200));

int maxDurationInmilliseconds =
await audioPlayer.fixedPlayer!.getDuration();
await audioPlayer.getDuration().then((value) =>
maxDuration = value ?? Duration.zero);

maxDuration = Duration(milliseconds: maxDurationInmilliseconds);
setState(() {
samples = samplesData["samples"];
});
Expand All @@ -83,20 +82,18 @@ class _HomeState extends State<Home> {
// While the values above them are good for showing [PolygonWaveform]
totalSamples = 1000;
audioData = audioDataList[0];
audioPlayer = AudioCache(
fixedPlayer: AudioPlayer(),
);
audioPlayer = AudioPlayer();

samples = [];
maxDuration = const Duration(milliseconds: 1000);
elapsedDuration = const Duration();
parseData();
audioPlayer.fixedPlayer!.onPlayerCompletion.listen((_) {
audioPlayer.onPlayerComplete.listen((_) {
setState(() {
elapsedDuration = maxDuration;
});
});
audioPlayer.fixedPlayer!.onAudioPositionChanged
audioPlayer.onPositionChanged
.listen((Duration timeElapsed) {
setState(() {
elapsedDuration = timeElapsed;
Expand Down Expand Up @@ -131,7 +128,7 @@ class _HomeState extends State<Home> {
children: [
ElevatedButton(
onPressed: () {
audioPlayer.fixedPlayer!.pause();
audioPlayer.pause();
},
child: const Icon(
Icons.pause,
Expand All @@ -140,15 +137,15 @@ class _HomeState extends State<Home> {
sizedBox,
ElevatedButton(
onPressed: () {
audioPlayer.fixedPlayer!.resume();
audioPlayer.resume();
},
child: const Icon(Icons.play_arrow),
),
sizedBox,
ElevatedButton(
onPressed: () {
setState(() {
audioPlayer.fixedPlayer!
audioPlayer
.seek(const Duration(milliseconds: 0));
});
},
Expand Down
57 changes: 28 additions & 29 deletions example/lib/waveforms_dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() {
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({super.key});

// This widget is the root of your application.
@override
Expand All @@ -27,7 +27,7 @@ class MyApp extends StatelessWidget {
}

class WaveformsDashboard extends StatefulWidget {
const WaveformsDashboard({Key? key}) : super(key: key);
const WaveformsDashboard({super.key});

@override
State<WaveformsDashboard> createState() => _WaveformsDashboardState();
Expand All @@ -36,9 +36,10 @@ class WaveformsDashboard extends StatefulWidget {
class _WaveformsDashboardState extends State<WaveformsDashboard> {
late Duration maxDuration;
late Duration elapsedDuration;
late AudioCache audioPlayer;
late AudioPlayer audioPlayer;
late List<double> samples;
double sliderValue = 0;

// Change this value to number of audio samples you want.
// Values between 256 and 1024 are good for showing [RectangleWaveform] and [SquigglyWaveform]
// While the values above them are good for showing [PolygonWaveform]
Expand Down Expand Up @@ -77,39 +78,36 @@ class _WaveformsDashboardState extends State<WaveformsDashboard> {
}

Future<void> playAudio() async {
await audioPlayer.load(audioData[1]);
await audioPlayer.play(audioData[1]);
await audioPlayer.setSourceAsset(audioData[1]);
await audioPlayer.resume();
// maxDuration in milliseconds
await Future.delayed(const Duration(milliseconds: 200));

int maxDurationInmilliseconds =
await audioPlayer.fixedPlayer!.getDuration();
await audioPlayer.getDuration()
.then((value) => maxDuration = value ?? Duration.zero);

maxDuration = Duration(milliseconds: maxDurationInmilliseconds);
}

@override
void initState() {
// TODO: implement initState
super.initState();
audioData = audioDataList[0];
audioPlayer = AudioCache(
fixedPlayer: AudioPlayer(),
);
audioPlayer = AudioPlayer();

parseData();

samples = [];
maxDuration = const Duration(milliseconds: 1000);
elapsedDuration = const Duration();

audioPlayer.fixedPlayer!.onPlayerCompletion.listen((_) {
audioPlayer.onPlayerComplete.listen((_) {
setState(() {
elapsedDuration = maxDuration;
sliderValue = 1;
});
});
audioPlayer.fixedPlayer!.onAudioPositionChanged.listen((Duration p) {
audioPlayer.onPositionChanged.listen((Duration p) {
setState(() {
elapsedDuration = p;
sliderValue = p.inMilliseconds / maxDuration.inMilliseconds;
Expand Down Expand Up @@ -273,15 +271,16 @@ class _WaveformsDashboardState extends State<WaveformsDashboard> {
// await audioPlayer.fixedPlayer!.resume();
},
onChangeStart: (double value) async {
await audioPlayer.fixedPlayer!.pause();
await audioPlayer.pause();
},
onChanged: (val) {
setState(() {
sliderValue = val;

audioPlayer.fixedPlayer!.seek(Duration(
audioPlayer.seek(Duration(
milliseconds:
(maxDuration.inMilliseconds * val).toInt()));

});
},
),
Expand Down Expand Up @@ -312,7 +311,7 @@ class _WaveformsDashboardState extends State<WaveformsDashboard> {
children: [
ElevatedButton(
onPressed: () {
audioPlayer.fixedPlayer!.pause();
audioPlayer.pause();
},
child: const Icon(
Icons.pause,
Expand All @@ -323,8 +322,8 @@ class _WaveformsDashboardState extends State<WaveformsDashboard> {
),
ElevatedButton(
onPressed: () async {
if (audioPlayer.fixedPlayer!.state == PlayerState.PAUSED) {
audioPlayer.fixedPlayer!.resume();
if (audioPlayer.state == PlayerState.paused) {
audioPlayer.resume();
} else {
await playAudio();
}
Expand All @@ -338,7 +337,7 @@ class _WaveformsDashboardState extends State<WaveformsDashboard> {
onPressed: () {
setState(() {
sliderValue = 0;
audioPlayer.fixedPlayer!
audioPlayer
.seek(const Duration(milliseconds: 0));
});
},
Expand Down Expand Up @@ -595,12 +594,12 @@ class _WaveformsDashboardState extends State<WaveformsDashboard> {
iconDisabledColor: Colors.white,
items: const [
DropdownMenuItem(
child: Text("Stroke"),
value: PaintingStyle.stroke,
child: Text("Stroke"),
),
DropdownMenuItem(
child: Text("Fill"),
value: PaintingStyle.fill,
child: Text("Fill"),
),
],
onChanged: (value) {
Expand Down Expand Up @@ -716,12 +715,12 @@ class _WaveformsDashboardState extends State<WaveformsDashboard> {

class SquigglyWaveformExample extends StatelessWidget {
const SquigglyWaveformExample({
Key? key,
super.key,
required this.maxDuration,
required this.elapsedDuration,
required this.samples,
required this.waveformCustomizations,
}) : super(key: key);
});

final Duration maxDuration;
final Duration elapsedDuration;
Expand All @@ -748,12 +747,12 @@ class SquigglyWaveformExample extends StatelessWidget {

class CurvedPolgonWaveformExample extends StatelessWidget {
const CurvedPolgonWaveformExample({
Key? key,
super.key,
required this.maxDuration,
required this.elapsedDuration,
required this.samples,
required this.waveformCustomizations,
}) : super(key: key);
});

final Duration maxDuration;
final Duration elapsedDuration;
Expand Down Expand Up @@ -781,12 +780,12 @@ class CurvedPolgonWaveformExample extends StatelessWidget {

class RectangleWaveformExample extends StatelessWidget {
const RectangleWaveformExample({
Key? key,
super.key,
required this.maxDuration,
required this.elapsedDuration,
required this.samples,
required this.waveformCustomizations,
}) : super(key: key);
});

final Duration maxDuration;
final Duration elapsedDuration;
Expand Down Expand Up @@ -819,12 +818,12 @@ class RectangleWaveformExample extends StatelessWidget {

class PolygonWaveformExample extends StatelessWidget {
const PolygonWaveformExample({
Key? key,
super.key,
required this.maxDuration,
required this.elapsedDuration,
required this.samples,
required this.waveformCustomizations,
}) : super(key: key);
});

final Duration maxDuration;
final Duration elapsedDuration;
Expand Down
6 changes: 3 additions & 3 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import FlutterMacOS
import Foundation

import audioplayers
import path_provider_macos
import audioplayers_darwin
import path_provider_foundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioplayersPlugin.register(with: registry.registrar(forPlugin: "AudioplayersPlugin"))
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
}
Loading