Closed aaayushsingh closed 2 years ago
Getting this too, so far no luck finding out why... it seems in debug mode the app doesn't crash even on device, only in release.
The issue can be replicated multiple times. When running with Xcode, it gives EXC_BAD_ACCESS
I tried tinkering with the code and the issue occurs with the AVAudioSessionDelegate. You can also see this in the screenshots of the crash log below that the error occurs at finishedPlaying.
My initial thought was this was because the WeakRef was somehow getting garbage collected(this was a past known issue with NativeScript) and attempts to access were thus resulting in EXC_BAD_ACCESS but I tried to change that and the crashes were still happening. If we however comment out the line that adds delegate to AVAudioPlayer, The app doesn't crash after the audio finishes playing.
Still not 100% sure about the cause of the error
@tomtastico I made a super hacky(and bad) fix that in no way should be taken to production unless extremely urgent. However, in my case it was urgent so I was left with no choice.
You can check out my fork and to add it to project use tns plugin add https://github.com/aaayushsingh/nativescript-audio
But avoid this unless necessary
In the end we switched to this fork of nativescript-sound
https://github.com/forgm/nativescript-sound and it works fine with no crashes in iOS. We don't need audio recording so this is enough for us.
@aaayushsingh did you find good solution ?
@aaayushsingh @govi2010 reading your comment on the cause of the issue i think it is because the delegate is not retained on the JS side. Changing
this._player.delegate = TNSPlayerDelegate.initWithOwner(this);
to
this.delegate = TNSPlayerDelegate.initWithOwner(this);
this._player.delegate = this.delegate;
could make it not crash however you must add the clearing of the delegate once the object is released
@farfromrefug Thank you for guidance. I am trying this right now. If it works then I will send PR.
The plugin works fine on iOS simulator but when running on an actual device, I'm getting random crashes and sometimes the audio finishes playing but the completeCallback never executes and app crashes in a few seconds.
The crashes happen after the audio finishes playing and never during the playback
edit: And there are no logs, even after setting debug to true