flutter_soloud icon indicating copy to clipboard operation
flutter_soloud copied to clipboard

fix: SoLoudBackendNotInitedException when soloud.init();

Open georgechond94 opened this issue 4 months ago • 13 comments

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

georgechond94 avatar Aug 06 '25 12:08 georgechond94

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();

  ...

alnitak avatar Aug 06 '25 13:08 alnitak

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

georgechond94 avatar Aug 06 '25 13:08 georgechond94

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

alnitak avatar Aug 06 '25 13:08 alnitak

Interesting, that actually helped, thanks!

georgechond94 avatar Aug 06 '25 14:08 georgechond94

@alnitak hmm, I just tried it with a release build and it happened again. 🫤

georgechond94 avatar Aug 06 '25 14:08 georgechond94

So it has been fixed in debug mode but still on release?

alnitak avatar Aug 06 '25 15:08 alnitak

Sorry for the late response - Yeah, exactly. The release build throws the same error

georgechond94 avatar Aug 07 '25 13:08 georgechond94

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

ineffablesam avatar Sep 24 '25 22:09 ineffablesam

We are having the exact same issue on version 3.3.7. FlutterError - SoLoudBackendNotInitedException: The player is not initialized (on the C++ side).

revtut avatar Oct 15 '25 07:10 revtut

Same here.

leonb2 avatar Oct 21 '25 17:10 leonb2

same here

LatCui avatar Nov 07 '25 12:11 LatCui

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.

LatCui avatar Nov 10 '25 03:11 LatCui

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.

dyaboykyl avatar Nov 24 '25 10:11 dyaboykyl