audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

PlatformException(DarwinAudioError, Error configuring audio session: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)", null, null)

Open nagringapp opened this issue 1 year ago • 6 comments

Checklist

  • [X] I read the troubleshooting guide before raising this issue
  • [X] I made sure that the issue I am raising doesn't already exist

Current bug behaviour

I often get the following error on my console.

lutter: ^[[38;5;196m┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…> flutter: ^[[38;5;196m│ PlatformException(DarwinAudioError, Error configuring audio session: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)", null, null)<…> flutter: ^[[38;5;196m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…> flutter: ^[[38;5;196m│ #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)<…> flutter: ^[[38;5;196m│ #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)<…> flutter: ^[[38;5;196m│ #2 <…> flutter: ^[[38;5;196m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…> flutter: ^[[38;5;196m│ ⛔ Global Error<…> flutter: ^[[38;5;196m└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…> flutter: ----------------FIREBASE CRASHLYTICS---------------- flutter: PlatformException(DarwinAudioError, Error configuring audio session: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)", null, null) flutter: #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7) #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18) flutter: ---------------------------------------------------- [Global Error] Global Error [Global Error] PlatformException (PlatformException(DarwinAudioError, Error configuring audio session: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)", null, null)) [Global Error] #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7) #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)

Expected behaviour

Playe without errors

Steps to reproduce

Just play the music - see code below

Code sample

Code sample
oid _initAudioPlayer(String url) async {
    
    try {
      
      _audioPlayer = AudioPlayer(playerId: _musicId);
      _audioPlayer.setAudioContext(const AudioContext(
        android: AudioContextAndroid(
          contentType: AndroidContentType.music,
          isSpeakerphoneOn: true,
          stayAwake: true,
          usageType: AndroidUsageType.media,
          audioFocus: AndroidAudioFocus.gainTransientExclusive
        ),
        iOS: AudioContextIOS(
          category: AVAudioSessionCategory.multiRoute,
          options: [
            AVAudioSessionOptions.allowAirPlay, 
            AVAudioSessionOptions.allowBluetooth,
            AVAudioSessionOptions.allowBluetoothA2DP,
            AVAudioSessionOptions.defaultToSpeaker,
            AVAudioSessionOptions.interruptSpokenAudioAndMixWithOthers
          ],
        )
      ));

      await _audioPlayer.play(UrlSource(url));
      
      
    } catch (e, s) {
      Log.error('EsquentaPlayer._init', e, s);

    }
  }

Affected platforms

Android, iOS

Platform details

No response

AudioPlayers Version

5.2.1

Build mode

debug

Audio Files/URLs/Sources

No response

Screenshots

No response

Logs

my relevant logs
Full Logs
my full logs or a link to a gist

Flutter doctor:

Output of: flutter doctor -v

Related issues / more information

No response

Working on PR

no way

nagringapp avatar Jan 03 '24 13:01 nagringapp

I am experiencing the same problem. Any update or work-around?

cgfischer avatar Jan 18 '24 02:01 cgfischer

I noticed in dev mode the app has been crashing a lot, but i couldt map the bug in production yet. (So im concerned if it will crash the user at some point).

No work around - kill the app and run it again that my workaround.

Kind Regards,

Thiago Bernardes Founder 0448 087 563 www.nagringa.app https://www.hungy.app/?utm_source=signature&utm_medium=email&utm_campaign=contact-tb

On Thu, 18 Jan 2024 at 12:33 pm, Chris Fischer @.***> wrote:

I am experiencing the same problem. Any update or work-around?

— Reply to this email directly, view it on GitHub https://github.com/bluefireteam/audioplayers/issues/1740#issuecomment-1897672816, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU6ICBCH6IWYUTAVF6SZY23YPCCY3AVCNFSM6AAAAABBLOOOTSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJXGY3TEOBRGY . You are receiving this because you authored the thread.Message ID: @.***>

nagringapp avatar Jan 18 '24 03:01 nagringapp

Any progress on this matter? Or workaround?

Interestingly I get the same error only when running on IOS in release mode (on physical device). However, I get no error when running in simulator in debug mode. So this is really annoying. While digging deeper I found that the error is reported from SwiftAudioPlayersDarwinPlugin.swift when the method is "setAudioContext". In my code I had the following line:

AudioPlayer.global.setAudioContext(audioContext)

which was causing the error and I could not get rid of it although I put in try/catch block. As I am using package Catcher to catch and report errors I found that the app is playing audio when I just continued after getting this error. So my solution was just to comment out setting audio context and everything works as supposed.

jozes avatar Jan 24 '24 07:01 jozes

By the way, I was checking my logs in production and I can see those events coming through. However, I don’t know if the app is crashing with the user.

Kind Regards,

Thiago Bernardes Founder 0448 087 563 www.nagringa.app https://www.hungy.app/?utm_source=signature&utm_medium=email&utm_campaign=contact-tb

On Wed, 24 Jan 2024 at 5:06 pm, Joze @.***> wrote:

Any progress on this matter? Or workaround?

Interestingly I get the same error only when running on IOS in release mode (on physical device). However, I get no error when running in simulator in debug mode. So this is really annoying. While digging deeper I found that the error is reported from SwiftAudioPlayersDarwinPlugin.swift when the method is "setAudioContext". In my code I had the following line:

AudioPlayer.global.setAudioContext(audioContext)

which was causing the error and I could not get rid of it although I put in try/catch block. As I am using package Catcher to catch and report errors I found that the app is playing audio when I just continued after getting this error. So my solution was just to comment this line and everything works as supposed.

— Reply to this email directly, view it on GitHub https://github.com/bluefireteam/audioplayers/issues/1740#issuecomment-1907490092, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU6ICBGIBDBC2AQXKL6HNIDYQCXGZAVCNFSM6AAAAABBLOOOTSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBXGQ4TAMBZGI . You are receiving this because you authored the thread.Message ID: @.***>

nagringapp avatar Jan 24 '24 07:01 nagringapp

@nagringapp In my app I am using Catcher to catch all uncaught exceptions and this one was always triggering Catcher to display the error to the app user. So in my case the app was crashing in a "controllable" way reporting an exception via Catcher screen. Interesting, no such exception is occurring in debug mode.

jozes avatar Jan 24 '24 08:01 jozes

Thank you for the detailed report. I currently have no OSX machine. But I try to solve this at some point. Don't hesitate trying to fix it and post a Merge Request. Thank you!

Gustl22 avatar Mar 16 '24 08:03 Gustl22