nstudio / nativescript-audio

:microphone: NativeScript plugin to record and play audio :musical_note:
Other
150 stars 104 forks source link

No sound in simulator (iOS) #200

Open sc00 opened 1 year ago

sc00 commented 1 year ago

Hey folks,

according to the console, my audio track is being played successfully:

reference back to player: <AVAudioPlayer: 0x600002c8c840> whether song play completed successfully: true

I hear no sound in simulator (iOs) though. Device volume is set to 100%. Sound in other apps works. I tried multiple files of different types (mp3, wav).

Any leads?

skopekreep commented 1 year ago

To second the above report, I also do not get sound from the iOS simulator, but it is working properly in connected physical test devices. I have just started on this project again after some time, so I cannot say when the simulator stopped working, but I am certain it did a couple years ago when I last used the plugin. I was able to play sound on a video in the simulator, so it is not a configuration or volume issue. Thank you for looking into this when you have a moment.

Details: iPhone 14 Pro Max Simulator iOS 16.2 "nativescript-audio": "^6.2.6",

kmahelona commented 1 year ago

I can get sound to come out of the simulator if I play AND record at the same time! On my iPhone, I can only get sound coming out of my airpods. If I use the speaker for playback for the iphone, no sound comes out. I suspect there's an issue with routing.

I also see this error popping up,

  setCategoryError: null, <Reference: 0x6000007dce90>

not sure if it's related.

kmahelona commented 1 year ago

This is the problem in the ios/player.js

               if (options.audioMixing) {
                    audioSession.setCategoryWithOptionsError(AVAudioSessionCategoryAmbient, 1);
                }
                else {
                    audioSession.setCategoryWithOptionsError(AVAudioSessionCategoryAmbient, 2);
                }

if you comment out those lines it will fix the problem.

You can see the docs for the ambient mixing, https://developer.apple.com/documentation/avfaudio/avaudiosessioncategoryambient. Presumably some people will want that feature, but if you set audioMixing: false the player still loads up the Ambient category. I'm not sure if that logic is correct because I'm not sure what the 1 or 2 they pass to the setCategoryWithOptionsError does.