From 4814631edfcc6bc9bcae569a481d512f7f2506c8 Mon Sep 17 00:00:00 2001 From: Marco Bavagnoli Date: Sat, 21 Dec 2024 16:28:43 +0100 Subject: [PATCH] removed temp example --- example/lib/main.dart | 155 ++++++-------------------- lib/src/bindings/bindings_player.dart | 3 +- lib/src/soloud.dart | 3 +- 3 files changed, 35 insertions(+), 126 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 8ef8297..eb46fc9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -36,6 +36,7 @@ void main() async { ); } +/// Simple usecase of flutter_soloud plugin class HelloFlutterSoLoud extends StatefulWidget { const HelloFlutterSoLoud({super.key}); @@ -45,139 +46,45 @@ class HelloFlutterSoLoud extends StatefulWidget { class _HelloFlutterSoLoudState extends State { AudioSource? currentSound; - final controller = TextEditingController(text: ''); - Timer? timer; - var xPos = 0.0; - Future init() async { - await SoLoud.instance.disposeAllSources(); - - currentSound = await SoLoud.instance.loadAsset( - 'assets/audio/8_bit_mentality.mp3', - ); - - timer?.cancel(); - - currentSound!.soundEvents.listen((data) { - print('EVENT $data'); - }); + @override + void dispose() { + SoLoud.instance.deinit(); + super.dispose(); } @override Widget build(BuildContext context) { - return Scaffold( - body: Column( - children: [ - ElevatedButton( - onPressed: () async { - await init(); - }, - child: const Text('init'), - ), - ElevatedButton( - onPressed: () async { - xPos = 0; - final newHandle = await SoLoud.instance.play3d( - currentSound!, - 0, - 0, - 0, - ); - - SoLoud.instance.set3dSourceMinMaxDistance(newHandle, 0, 10); - SoLoud.instance.set3dSourceAttenuation(newHandle, 2, 1); - - SoLoud.instance.setInaudibleBehavior(newHandle, false, true); - - timer = Timer.periodic( - const Duration(milliseconds: 100), - (_) { - controller.text = ''; - for (final handle in currentSound!.handles) { - print('HANDLE $handle'); - controller.text += - '\n$handle - X pos: ${xPos.toStringAsFixed(1)} - ' - 'time: ${SoLoud.instance.getPosition(handle).inMilliseconds}'; + if (!SoLoud.instance.isInitialized) return const SizedBox.shrink(); - SoLoud.instance.set3dSourcePosition( - handle, - xPos += 0.1, - 0, - 0, - ); - } - }, + return Scaffold( + body: Center( + child: ElevatedButton( + onPressed: () async { + await SoLoud.instance.disposeAllSources(); + + if (kIsWeb) { + /// load the audio file using [LoadMode.disk] (better for the + /// Web platform). + currentSound = await SoLoud.instance.loadAsset( + 'assets/audio/8_bit_mentality.mp3', + mode: LoadMode.disk, ); - - // Timer.periodic(const Duration(milliseconds: 2000), (timer) { - // timer.cancel(); - // for (final handle in currentSound!.handles) { - // SoLoud.instance.setVolume(handle, 0.001); - // } - // }); - }, - child: const Text('play'), - ), - TextField( - controller: controller, - minLines: 5, - maxLines: 20, + } else { + /// load the audio file + currentSound = await SoLoud.instance + .loadAsset('assets/audio/8_bit_mentality.mp3'); + } + + /// play it + await SoLoud.instance.play(currentSound!); + }, + child: const Text( + 'play asset', + textAlign: TextAlign.center, ), - ], + ), ), ); } } - -// /// Simple usecase of flutter_soloud plugin -// class HelloFlutterSoLoud extends StatefulWidget { -// const HelloFlutterSoLoud({super.key}); - -// @override -// State createState() => _HelloFlutterSoLoudState(); -// } - -// class _HelloFlutterSoLoudState extends State { -// AudioSource? currentSound; - -// @override -// void dispose() { -// SoLoud.instance.deinit(); -// super.dispose(); -// } - -// @override -// Widget build(BuildContext context) { -// if (!SoLoud.instance.isInitialized) return const SizedBox.shrink(); - -// return Scaffold( -// body: Center( -// child: ElevatedButton( -// onPressed: () async { -// await SoLoud.instance.disposeAllSources(); - -// if (kIsWeb) { -// /// load the audio file using [LoadMode.disk] (better for the -// /// Web platform). -// currentSound = await SoLoud.instance.loadAsset( -// 'assets/audio/8_bit_mentality.mp3', -// mode: LoadMode.disk, -// ); -// } else { -// /// load the audio file -// currentSound = await SoLoud.instance -// .loadAsset('assets/audio/8_bit_mentality.mp3'); -// } - -// /// play it -// await SoLoud.instance.play(currentSound!); -// }, -// child: const Text( -// 'play asset', -// textAlign: TextAlign.center, -// ), -// ), -// ), -// ); -// } -// } diff --git a/lib/src/bindings/bindings_player.dart b/lib/src/bindings/bindings_player.dart index bc3de56..e630ea2 100644 --- a/lib/src/bindings/bindings_player.dart +++ b/lib/src/bindings/bindings_player.dart @@ -525,7 +525,8 @@ abstract class FlutterSoLoud { /// ticking the sound even if it's inaudible. /// /// [handle] handle to check. - /// [mustTick] whether to keep ticking or not when the sound becomes inaudible. + /// [mustTick] whether to keep ticking or not when the sound becomes + /// inaudible. /// [kill] whether to kill the sound or not when the sound becomes inaudible. @mustBeOverridden void setInaudibleBehavior(SoundHandle handle, bool mustTick, bool kill); diff --git a/lib/src/soloud.dart b/lib/src/soloud.dart index 8a82d1b..2dd8d2f 100644 --- a/lib/src/soloud.dart +++ b/lib/src/soloud.dart @@ -1618,7 +1618,8 @@ interface class SoLoud { /// ticking the sound even if it's inaudible. /// /// [handle] handle to check. - /// [mustTick] whether to keep ticking or not when the sound becomes inaudible. + /// [mustTick] whether to keep ticking or not when the sound becomes + /// inaudible. /// [kill] whether to kill the sound or not when the sound becomes inaudible. /// /// **Example**: