Skip to content

Commit

Permalink
removed temp example
Browse files Browse the repository at this point in the history
  • Loading branch information
alnitak committed Dec 21, 2024
1 parent 9285848 commit 4814631
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 126 deletions.
155 changes: 31 additions & 124 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void main() async {
);
}

/// Simple usecase of flutter_soloud plugin
class HelloFlutterSoLoud extends StatefulWidget {
const HelloFlutterSoLoud({super.key});

Expand All @@ -45,139 +46,45 @@ class HelloFlutterSoLoud extends StatefulWidget {

class _HelloFlutterSoLoudState extends State<HelloFlutterSoLoud> {
AudioSource? currentSound;
final controller = TextEditingController(text: '');
Timer? timer;
var xPos = 0.0;

Future<void> 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<HelloFlutterSoLoud> createState() => _HelloFlutterSoLoudState();
// }

// class _HelloFlutterSoLoudState extends State<HelloFlutterSoLoud> {
// 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,
// ),
// ),
// ),
// );
// }
// }
3 changes: 2 additions & 1 deletion lib/src/bindings/bindings_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/src/soloud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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**:
Expand Down

0 comments on commit 4814631

Please sign in to comment.