Closed fangjunai closed 1 year ago
When the music has not been played yet, clicking play again will cause an error.
Win10 x64 PS C:\Windows\system32> flutter --version Flutter 3.10.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 9cd3d0d9ff (9 weeks ago) • 2023-05-23 20:57:28 -0700 Engine • revision 90fa3ae28f Tools • Dart 3.0.2 • DevTools 2.23.1 PS C:\Windows\system32>
import 'package:flutter/material.dart'; import "package:minisound/minisound.dart" as minisound; class Test2 extends StatefulWidget { const Test2({Key? key}) : super(key: key); @override _Test2State createState() => _Test2State(); } class _Test2State extends State<Test2> { @override Widget build(BuildContext context) { final engine = minisound.Engine(); return Scaffold( appBar: AppBar( title: const Text('Test Play'), ), body: ElevatedButton( child: const Text("play"), onPressed: () async { await engine.init(); final sound = await engine .loadSoundFile("C:\\Users\\FangJun\\Music\\我会好好的 - 王心凌.mp3"); await engine.start(); sound.play(); }, ), ); } }
Flutter assets will be downloaded from https://mirrors.tuna.tsinghua.edu.cn/flutter. Make sure you trust this source! Launching lib\main.dart on Windows in debug mode... √ Built build\windows\runner\Debug\fmusic.exe. Connecting to VM Service at ws://127.0.0.1:10766/YcJzBaabtFU=/ws DEBUG: Loading library: user32.dll DEBUG: Loading symbol: GetForegroundWindow DEBUG: Loading symbol: GetDesktopWindow DEBUG: Loading library: advapi32.dll DEBUG: Loading symbol: RegOpenKeyExA DEBUG: Loading symbol: RegCloseKey DEBUG: Loading symbol: RegQueryValueExA DEBUG: Loading library: ole32.dll DEBUG: Loading symbol: CoInitialize DEBUG: Loading symbol: CoInitializeEx DEBUG: Loading symbol: CoUninitialize DEBUG: Loading symbol: CoCreateInstance DEBUG: Loading symbol: CoTaskMemFree DEBUG: Loading symbol: PropVariantClear DEBUG: Loading symbol: StringFromGUID2 DEBUG: Attempting to initialize WASAPI backend... DEBUG: Loading library: kernel32.dll DEBUG: Loading symbol: VerifyVersionInfoW DEBUG: Loading symbol: VerSetConditionMask DEBUG: Loading library: avrt.dll DEBUG: Loading symbol: AvSetMmThreadCharacteristicsA DEBUG: Loading symbol: AvRevertMmThreadCharacteristics DEBUG: System Architecture: DEBUG: Endian: LE DEBUG: SSE2: YES DEBUG: AVX2: YES DEBUG: NEON: NO DEBUG: [WASAPI] Trying IAudioClient3_InitializeSharedAudioStream(actualPeriodInFrames=441) DEBUG: defaultPeriodInFrames=441 DEBUG: fundamentalPeriodInFrames=441 DEBUG: minPeriodInFrames=441 DEBUG: maxPeriodInFrames=441 DEBUG: [WASAPI] Using IAudioClient3 DEBUG: periodSizeInFramesOut=441 INFO: [WASAPI] INFO: 扬声器 (USB Audio Device) (Playback) INFO: Format: 32-bit IEEE Floating Point -> 32-bit IEEE Floating Point INFO: Channels: 2 -> 2 INFO: Sample Rate: 44100 -> 44100 INFO: Buffer Size: 441*3 (1323) INFO: Conversion: INFO: Pre Format Conversion: NO INFO: Post Format Conversion: NO INFO: Channel Routing: NO INFO: Resampling: NO INFO: Passthrough: YES INFO: Channel Map In: {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT} INFO: Channel Map Out: {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT} [engine.c:63 info] engine initialized successfully! [engine.c:109 info] sound loaded successfully! [engine.c:83 info] engine started successfully [engine.c:132 info] sound played successfully! DEBUG: Loading library: user32.dll DEBUG: Loading symbol: GetForegroundWindow DEBUG: Loading symbol: GetDesktopWindow DEBUG: Loading library: advapi32.dll DEBUG: Loading symbol: RegOpenKeyExA DEBUG: Loading symbol: RegCloseKey DEBUG: Loading symbol: RegQueryValueExA DEBUG: Loading library: ole32.dll DEBUG: Loading symbol: CoInitialize DEBUG: Loading symbol: CoInitializeEx DEBUG: Loading symbol: CoUninitialize DEBUG: Loading symbol: CoCreateInstance DEBUG: Loading symbol: CoTaskMemFree DEBUG: Loading symbol: PropVariantClear DEBUG: Loading symbol: StringFromGUID2 DEBUG: Attempting to initialize WASAPI backend... DEBUG: Loading library: kernel32.dll DEBUG: Loading symbol: VerifyVersionInfoW DEBUG: Loading symbol: VerSetConditionMask DEBUG: Loading library: avrt.dll DEBUG: Loading symbol: AvSetMmThreadCharacteristicsA DEBUG: Loading symbol: AvRevertMmThreadCharacteristics DEBUG: System Architecture: DEBUG: Endian: LE DEBUG: SSE2: YES DEBUG: AVX2: YES DEBUG: NEON: NO DEBUG: [WASAPI] Trying IAudioClient3_InitializeSharedAudioStream(actualPeriodInFrames=441) DEBUG: defaultPeriodInFrames=441 DEBUG: fundamentalPeriodInFrames=441 DEBUG: minPeriodInFrames=441 DEBUG: maxPeriodInFrames=441 DEBUG: [WASAPI] Using IAudioClient3 DEBUG: periodSizeInFramesOut=441 INFO: [WASAPI] INFO: 扬声器 (USB Audio Device) (Playback) INFO: Format: 32-bit IEEE Floating Point -> 32-bit IEEE Floating Point INFO: Channels: 2 -> 2 INFO: Sample Rate: 44100 -> 44100 INFO: Buffer Size: 441*3 (1323) INFO: Conversion: INFO: Pre Format Conversion: NO INFO: Post Format Conversion: NO INFO: Channel Routing: NO INFO: Resampling: NO INFO: Passthrough: YES INFO: Channel Map In: {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT} INFO: Channel Map Out: {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT} Lost connection to device. [engine.c:63 i Exited (sigterm)
I think this happens because you are trying to initialize an engine multiple times. Moving initialization to the start of main or at least widget's initState should solve the problem.
main
initState
When the music has not been played yet, clicking play again will cause an error.
Win10 x64 PS C:\Windows\system32> flutter --version Flutter 3.10.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 9cd3d0d9ff (9 weeks ago) • 2023-05-23 20:57:28 -0700 Engine • revision 90fa3ae28f Tools • Dart 3.0.2 • DevTools 2.23.1 PS C:\Windows\system32>
code
error: