flutter_soloud
flutter_soloud copied to clipboard
fix: SoLoudBackendNotInitedException when soloud.init();
Description
Hi, thanks for the great package!
I just updated soloud to the latest version (3.2.4) and I started getting the following error when calling soloud.init();
SoLoudBackendNotInitedException (SoLoudBackendNotInitedException: The player is not initialized (on the C++ side).)
Any idea why? Thanks
Hi @georgechond94, can you give some more info? I am more interested in the platform where you are seeing this issue and if it is relevant, some code. Also, the init method is the first soloud method you are calling?
To see some more log info, you can try to use the logging package:
in the pubspec add it: dart pub add logging.
Then in your main.dart:
import 'dart:developer' as dev;
import 'package:logging/logging.dart';
...
void main() async {
Logger.root.level = kDebugMode ? Level.FINEST : Level.INFO;
Logger.root.onRecord.listen((record) {
dev.log(
record.message,
time: record.time,
level: record.level.value,
name: record.loggerName,
zone: record.zone,
error: record.error,
stackTrace: record.stackTrace,
);
});
WidgetsFlutterBinding.ensureInitialized();
/// Initialize the player.
await SoLoud.instance.init();
...
Hi @alnitak, thank you for the quick response.
I am using a physical iOS device and init() is the first method I am calling (along with flutter_recorder's init() and AudioSession's configure.)
await _soloud.init(channels: Channels.mono, sampleRate: 24000); // this line throws the error.
await _recorder.init(
sampleRate: 24000,
channels: recorder.RecorderChannels.mono,
format: recorder.PCMFormat.s16le,
);
_session = await AudioSession.instance;
await _session.configure(AudioSessionConfiguration(
avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
avAudioSessionCategoryOptions:
AVAudioSessionCategoryOptions.allowBluetooth,
avAudioSessionMode: AVAudioSessionMode.voiceChat,
avAudioSessionRouteSharingPolicy:
AVAudioSessionRouteSharingPolicy.defaultPolicy,
avAudioSessionSetActiveOptions:
AVAudioSessionSetActiveOptions.notifyOthersOnDeactivation,
androidAudioAttributes: const AndroidAudioAttributes(
contentType: AndroidAudioContentType.speech,
flags: AndroidAudioFlags.none,
usage: AndroidAudioUsage.voiceCommunication,
),
androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
androidWillPauseWhenDucked: true,
));
I set up logging as you suggested, I ll come back with some more info soon
I am not sure, but since I changed the iOS podspec file, maybe you can also try a deeper clean of the pods. I used this script:
flutter clean
cd ios
rm -rf Pods
rm -rf Podfile.lock
pod install --repo-update
cd ..
flutter pub get
Interesting, that actually helped, thanks!
@alnitak hmm, I just tried it with a release build and it happened again. 🫤
So it has been fixed in debug mode but still on release?
Sorry for the late response - Yeah, exactly. The release build throws the same error
Same issue with version 3.3.0 on iOS in production: Crashes at about 1% of my iOS users. 20 Users effected so far.
Any ideas on how to fix or workaround it would be greatly appreciated.
flutter: SoLoud init failed ❌ SoLoudBackendNotInitedException: The player is not initialized (on the C++ side). flutter: #0 SoLoud.init (package:flutter_soloud/src/soloud.dart:297:7) flutter: <asynchronous suspension> flutter: #1 main (package:example/main.dart:24:5) flutter: <asynchronous suspension>
Still the same error. using version flutter_soloud: 3.3.4
We are having the exact same issue on version 3.3.7.
FlutterError - SoLoudBackendNotInitedException: The player is not initialized (on the C++ side).
Same here.
same here
I have identified the reproducibility steps. Every time I open the app, I put it in the background immediately, and then reopen the app. There is a small chance that I can reproduce the problem this way.
We are also seeing this error happen in production. I have added retries to the flutter init in case there was some race condition but it does not seem to help.