flutter_sound icon indicating copy to clipboard operation
flutter_sound copied to clipboard

[BUG]: iOS - Multiple Flutter Sound Player instances - starting player crash

Open Vedranivic opened this issue 2 years ago • 5 comments

Flutter Sound Version :

  • FULL
  • Result of the command : flutter pub deps | grep flutter_sound |-- flutter_sound 9.2.13 | |-- flutter_sound_platform_interface 9.2.13 | |-- flutter_sound_web 9.2.13 | | |-- flutter_sound_platform_interface...

Severity

  • Crash

Platforms you faced the error

  • iOS (14.7.1)

  • Real device (iPhone 11)


Bug description The app crashes when starting multiple instances of FlutterSoundPlayer: ─────────────────────────────────────────────────────────── [aurioc] AURemoteIO.cpp:1097:Initialize: failed: -66635 (enable 3, outf< 1 ch, 0 Hz, Float32> inf< 1 ch, 0 Hz, Float32>) [avae] AVAEInternal.h:76 required condition is false: [AVAudioEngineGraph.mm:2128:_Connect: (IsFormatSampleRateAndChannelCountValid(format))] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)' *** First throw call stack: (0x1966a6708 0x1ab1b07a8 0x1965a83b8 0x1e3a39d2c 0x1e3a7cfd0 0x1e3a847e8 0x1e3b03820 0x1e3b05864 0x106554538 0x106551b30 0x10340b7c0 0x10340d7d8 0x106d72fd0 0x10685df6c 0x108cfc0b4 0x108cfdde0 0x108d0e0a8 0x196620340 0x19661a218 0x196619308 0x1adc9c734 0x19909775c 0x19909cfcc 0x1033defbc 0x1962d5cf8) libc++abi: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)' terminating with uncaught exception of type NSException ─────────────────────────────────────────────────────────── I have had a similar crash before with FlutterSound Player and as many suggested setting the AVAudioSession category (in native objC code:[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:&error];) prior to calling .startPlayerFromStream() did in fact help remove this crash. However, when using multiple instances (two in this example), the AVAudioSession category remains the said one but the problem persists.

To Reproduce Steps to reproduce the behavior:

  1. Create first instance of Flutter Sound Player
  2. Create second instance of FSP
  3. Call .openPlayer() on first instance
  4. Call .openPlayer() on second instance
  5. Call startPlayerFromStream(codec: Codec.pcm16, sampleRate: 16000); on first instance (the audio plays properly)
  6. Call startPlayerFromStream(codec: Codec.pcm16, sampleRate: 16000); on second instance while the first one is still playing -> CRASH
  7. See error

Logs!!!!

2022-05-25 23:23:55.012348+0200 Runner[2426:1995871] flutter: │ #0 FlutterSoundPlayer.log (package:flutter_sound/public/flutter_sound_player.dart:360:13) 2022-05-25 23:23:55.012367+0200 Runner[2426:1995871] flutter: │ #1 MethodChannelFlutterSoundPlayer.channelMethodCallHandler (package:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:137:19) 2022-05-25 23:23:55.012388+0200 Runner[2426:1995871] flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ 2022-05-25 23:23:55.012501+0200 Runner[2426:1995871] flutter: │ 🐛 iOS: invokeMethod needSomeFood - state=1 2022-05-25 23:23:55.012563+0200 Runner[2426:1995871] flutter: └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.012851+0200 Runner[2426:1995871] flutter: ┌─────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.012851+0200 Runner[2426:1995871] flutter: ┌───────────────────────────────────\342\224──────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.012878+0200 Runner[2426:1995871] flutter: │ #0 FlutterSoundPlayer.log (package:flutter_sound/public/flutter_sound_player.dart:360:13) 2022-05-25 23:23:55.012899+0200 Runner[2426:1995871] flutter: │ #1 MethodChannelFlutterSoundPlayer.channelMethodCallHandler (package:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:137:19) 2022-05-25 23:23:55.012950+0200 Runner[2426:1995871] flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ 2022-05-25 23:23:55.013034+0200 Runner[2426:1995871] flutter: │ 🐛 IOS:--> startPlayer 2022-05-25 23:23:55.013125+0200 Runner[2426:1995871] flutter: └──────────────────────┄┄┄┄┄┄┄┄┄┄ 2022-05-25 23:23:55.013034+0200 Runner[2426:1995871] flutter: │ 🐛 IOS:--> startPlayer 2022-05-25 23:23:55.013125+0200 Runner[2426:1995871] flutter: └──────────────────────\342\224───────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.013301+0200 Runner[2426:1995871] flutter: ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.013368+0200 Runner[2426:1995871] flutter: │ #0 FlutterSoundPlayer.log (package:flutter_sound/public/flutter_sound_player.dart:360:13) 2022-05-25 23:23:55.013605+0200 Runner[2426:1995871] flutter: │ #1 MethodChannelFlutterSoundPlayer.channelMethodCallHandler (package:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:137:19) 2022-05-25 23:23:55.013844+0200 Runner[2426:1995871] flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ 2022-05-25 23:23:55.013948+0200 Runner[2426:1995871] flutter: │ 🐛 IOS:--> startPlayer 2022-05-25 23:23:55.014042+0200 Runner[2426:1995871] flutter: └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.014274+0200 Runner[2426:1995871] flutter: ┌────────────────────────────────────────────────────────────────────┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ 2022-05-25 23:23:55.013948+0200 Runner[2426:1995871] flutter: │ 🐛 IOS:--> startPlayer 2022-05-25 23:23:55.014042+0200 Runner[2426:1995871] flutter: └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.014274+0200 Runner[2426:1995871] flutter: ┌────────────────────────────────────────────────────────────────────\342─────────────────────────────────────────────────── 2022-05-25 23:23:55.014832+0200 Runner[2426:1995871] flutter: │ #0 FlutterSoundPlayer.log (package:flutter_sound/public/flutter_sound_player.dart:360:13) 2022-05-25 23:23:55.014854+0200 Runner[2426:1995871] flutter: │ #1 MethodChannelFlutterSoundPlayer.channelMethodCallHandler (package:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:137:19) 2022-05-25 23:23:55.014873+0200 Runner[2426:1995871] flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ 2022-05-25 23:23:55.014890+0200 Runner[2426:1995871] flutter: │ ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ 2022-05-25 23:23:55.013948+0200 Runner[2426:1995871] flutter: │ 🐛 IOS:--> startPlayer 2022-05-25 23:23:55.014042+0200 Runner[2426:1995871] flutter: └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.014274+0200 Runner[2426:1995871] flutter: ┌────────────────────────────────────────────────────────────────────\342─────────────────────────────────────────────────── 2022-05-25 23:23:55.014832+0200 Runner[2426:1995871] flutter: │ #0 FlutterSoundPlayer.log (package:flutter_sound/public/flutter_sound_player.dart:360:13) 2022-05-25 23:23:55.014854+0200 Runner[2426:1995871] flutter: │ #1 MethodChannelFlutterSoundPlayer.channelMethodCallHandler (package:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:137:19) 2022-05-25 23:23:55.014873+0200 Runner[2426:1995871] flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ 2022-05-25 23:23:55.014890+0200 Runner[2426:1995871] flutter: │ \360🐛 IOS:--> stopTimer 2022-05-25 23:23:55.014909+0200 Runner[2426:1995871] flutter: └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.015416+0200 Runner[2426:1995871] flutter: ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.015439+0200 Runner[2426:1995871] flutter: │ #0 FlutterSoundPlayer.log (package:flutter_sound/public/flutter_sound_player.dart:360:13) 2022-05-25 23:23:55.015458+0200 Runner[2426:1995871] flutter: │ #1 MethodChannelFlutterSoundPlayer.channelMethodCallHandler (package:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:137:19) 2022-05-25 23:23:55.015901+0200 Runner[2426:1995871] flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ 2022-05-25 23:23:55.015922+0200 Runner[2426:1995871] flutter: │ 🐛 IOS:<-- stopTimer 2022-05-25 23:23:55.015942+0200 Runner[2426:1995871] flutter: └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.017882+0200 Runner[2426:1995631] [aurioc] AURemoteIO.cpp:1097:Initialize: failed: -66635 (enable 3, outf< 1 ch, 0 Hz, Float32> inf< 1 ch, 0 Hz, Float32>)

2022-05-25 23:23:55.021026+0200 Runner[2426:1995631] [avae] AVAEInternal.h:76 required condition is false: [AVAudioEngineGraph.mm:2128:_Connect: (IsFormatSampleRateAndChannelCountValid(format))] 2022-05-25 23:23:55.021150+0200 Runner[2426:1995871] flutter: ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.021178+0200 Runner[2426:1995871] flutter: │ #0 FlutterSoundPlayer.log (package:flutter_sound/public/flutter_sound_player.dart:360:13) 2022-05-25 23:23:55.021200+0200 Runner[2426:1995871] flutter: │ #1 MethodChannelFlutterSoundPlayer.channelMethodCallHandler (package:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:137:19) 2022-05-25 23:23:55.021220+0200 Runner[2426:1995871] flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ CallId: 2022-05-25 23:23:55.021264+0200 Runner[2426:1995871] flutter: │ 🐛 VoiceProcessing enabled 2022-05-25 23:23:55.021286+0200 Runner[2426:1995871] flutter: └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 2022-05-25 23:23:55.021537+0200 Runner[2426:1995631] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)' *** First throw call stack: (0x1966a6708 0x1ab1b07a8 0x1965a83b8 0x1e3a39d2c 0x1e3a7cfd0 0x1e3a847e8 0x1e3b03820 0x1e3b05864 0x106554538 0x106551b30 0x10340b7c0 0x10340d7d8 0x106d72fd0 0x10685df6c 0x108cfc0b4 0x108cfdde0 0x108d0e0a8 0x196620340 0x19661a218 0x196619308 0x1adc9c734 0x19909775c 0x19909cfcc 0x1033defbc 0x1962d5cf8) libc++abi: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)' terminating with uncaught exception of type NSException (lldb)


Vedranivic avatar May 25 '22 21:05 Vedranivic

@Larpoux @hyochan @bsutton @JoniDS @ened @Mateis @mansya Can you please look into this issue?

Vedranivic avatar Jun 01 '22 06:06 Vedranivic

I did some debugging of flutter_sound_core and flutter_sound source code and it turns out the critical error was [aurioc] AURemoteIO.cpp:1097:Initialize: failed: -66635 (enable 3, outf< 1 ch, 0 Hz, Float32> inf< 1 ch, 0 Hz, Float32>) which I think was thrown on FlautoPlayerEngine:179 -> if (![outputNode setVoiceProcessingEnabled:YES error:&err]) {. Commenting the voice processing enabling part of the code did the trick and multiple instances of FSP seem to work just fine. The underlying issue however is the bug where the voiceProcessingEnabled flag evaluates to true no matter what gets sent from the dart/app side (true or false). I have forked a repo and made a bug fix to map the voiceProcessingEnabled flag on iOS properly on objective C side and have created a Pull request.

vedranivicatos avatar Jun 03 '22 12:06 vedranivicatos

This however is rather a patch not a real fix of the problem. The mention bug fix in PR is needed regardless. However, I believe the plugin needs some more investigation on why multiple instances cannot work with voice processing enabled, so I think this issue should remain open until resolved properly.

vedranivicatos avatar Jun 03 '22 12:06 vedranivicatos

I have this issue too. any update? I used this package to play the streaming audio data from the microphone. here is the code:

  Future<void> _startStreaming() async {
    stream = await MicStream.microphone(
      sampleRate: 16000,
      channelConfig: ChannelConfig.CHANNEL_IN_MONO,
      audioFormat: AudioFormat.ENCODING_PCM_16BIT,
    );

    stream!.listen((Uint8List audioData) async {
      player = (await FlutterSoundPlayer()
          .openPlayer(enableVoiceProcessing: false))!;

      await player.startPlayer(
          codec: Codec.pcm16,
          numChannels: 1,
          sampleRate: 16000,
          fromDataBuffer: audioData);
    });
  }

ParhaMDeF avatar Oct 19 '23 17:10 ParhaMDeF

how has no one run into this yet? I'm still getting issues? Why is this not fixed? Can we please get some movement on this? thanks! @Larpoux @hyochan @bsutton @JoniDS @ened @Mateis @mansya

D10100111001 avatar Jan 05 '24 08:01 D10100111001