File tree Expand file tree Collapse file tree 2 files changed +17
-19
lines changed Expand file tree Collapse file tree 2 files changed +17
-19
lines changed Original file line number Diff line number Diff line change 1
1
import 'dart:developer' as dev;
2
- import 'dart:io' ;
3
2
4
3
import 'package:flutter/foundation.dart' ;
5
4
import 'package:flutter/material.dart' ;
@@ -61,24 +60,23 @@ class _HelloFlutterSoLoudState extends State<HelloFlutterSoLoud> {
61
60
body: Center (
62
61
child: ElevatedButton (
63
62
onPressed: () async {
64
- // read the file bytes from "home/deimos/8/sample-1.ogg"
65
- // final f = File('/home/deimos/8/sample-1.ogg');
66
- // final bytes = f.readAsBytesSync();
63
+ await SoLoud .instance.disposeAllSources ();
67
64
68
- // final waveformData = await SoLoud.instance.readSamplesFromMem(
69
- // bytes,
70
- // 2000,
71
- // // average: true, // Average samples to smooth out the waveform
72
- // );
65
+ if (kIsWeb) {
66
+ /// load the audio file using [LoadMode.disk] (better for the
67
+ /// Web platform).
68
+ currentSound = await SoLoud .instance.loadAsset (
69
+ 'assets/audio/8_bit_mentality.mp3' ,
70
+ mode: LoadMode .disk,
71
+ );
72
+ } else {
73
+ /// load the audio file
74
+ currentSound = await SoLoud .instance
75
+ .loadAsset ('assets/audio/8_bit_mentality.mp3' );
76
+ }
73
77
74
- final waveformData = await SoLoud .instance.readSamplesFromFile (
75
- '/home/deimos/8/sample-1.ogg' ,
76
- 2000 ,
77
- // average: true, // Average samples to smooth out the waveform
78
- );
79
- bool b;
80
- b = true ;
81
- print (b);
78
+ /// play it
79
+ await SoLoud .instance.play (currentSound! );
82
80
},
83
81
child: const Text (
84
82
'play asset' ,
Original file line number Diff line number Diff line change @@ -1099,14 +1099,14 @@ class FlutterSoLoudWeb extends FlutterSoLoud {
1099
1099
final jsHeapF32 = wasmHeapF32Buffer;
1100
1100
// Convert the TypedArray view to a Dart Float32List
1101
1101
final samples = Float32List .sublistView (
1102
- jsHeapF32.toDart,
1102
+ jsHeapF32.toDart,
1103
1103
samplesPtr ~ / 4 , // divide by 4 because Float32 is 4 bytes
1104
1104
(samplesPtr ~ / 4 ) + numSamplesNeeded,
1105
1105
);
1106
1106
1107
1107
wasmFree (samplesPtr);
1108
1108
wasmFree (bufferPtr);
1109
-
1109
+
1110
1110
if (ReadSamplesErrors .fromValue (error) !=
1111
1111
ReadSamplesErrors .readSamplesNoError) {
1112
1112
throw SoLoudCppException .fromReadSampleError (
You can’t perform that action at this time.
0 commit comments