-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AVPlayerItem addOutput:] Cannot attach an output that is already attached. #1818
[AVPlayerItem addOutput:] Cannot attach an output that is already attached. #1818
Comments
Thoughts @jspizziri ? |
I also meet this crash in production. (cannot reproduce in debug) |
I have been looking at this and I think it is related to the NativeModule on iOS
The native modules can be loaded more than once, then |
Hi Everyone, We have the same issue on our project not in production but in dev environment. Did someone manage to fix this issue? |
We are having this crash too. |
Can anyone provide steps that we can easily reproduce this crash? Otherwise it is impossible to verify a fix. |
Hi @puckey, I think the best way of testing it is as I explained in my answer, is instantiating multiple times
to this
|
@pabloromeu thanks for the suggestion – this looks good.. I can make a pr with this fix. I just want to be able to reproduce the issue.. How would I go about instantiating |
@pabloromeu you would get: |
@pabloromeu any chance you could give instructions on how to replicate this issue? tia |
@mikeleruo yes, obviously. If you go for a singleton instance you need to use @puckey in my case, I was using RNTrackPlayer in a wrapper service on javascript side. For example:
So, each time I instantiate I got rid from the error by instantiating |
@pabloromeu , the documentation is (or at least used to be) very clear on not instantiating the track player multiple times for this very reason. While I agree implementing a singleton would make the library more ergonomic, I don't think this is a big, but rather confusion resulting in misuse and a subsequent feature request. I'm going to relabel it as such. |
@pabloromeu I don't believe your code wouldn't reinstantiate |
@pabloromeu just to be certain, have you tested this issue on the |
No @puckey I did not. I just ensured -as @jspizziri suggested- that I do not import the native library in two different places or times. I created a singleton in the JavaScript side and that worked for me. |
@pabloromeu i didn't say you couldn't import the library multiple times, I said you can't instantiate the player multiple times (which is what setupplayer does). At this point I would say you need to provide a reproduction in code or my vote is to close this issue. |
Agreed. Without code to reproduce let’s close this. This doesn’t appear to be a bug but a misconfiguration. Thanks all! |
This issue is a feature request to prevent a common misconfiguration of RNTP. While it does make the library more ergonomic I don't consider it to be an urgent feature. I'm going to close it for now, if someone wants to contribute to add this quality-of-life improvement please let us know and we can help guide you on the implementation. |
Hi, I have the same issue in my project. I am using |
@kubatatami if you create a reproduction in the example project by forking we can reopen. We won't reopen until there's a repro though. |
@bradleyflood our current recommendation is how we do it in the example app. Have you wrapped |
@bradleyflood have you verified that your particular issue is only happening on iOS 15+ |
@jspizziri : Thanks for pointing out the sample's try/catch bit. Hadn't realized the Android background-start bug existed. In that app, Is my suggestion in #1818 (comment) the right way to resolve this (i.e. once I add the try/catch/Android-sleep business)? |
@fivecar setup the player as soon as possible |
@fivecar Also you aren't actually calling any |
@bradleyflood - Ah, interesting. I had taken the documentation literally when it says, "Make sure the setup method has completed before interacting with any other functions [emphasis mine] in TrackPlayer." Combining yours and @jspizziri's suggestions together, it sounds like the approach I asked about in #1818 (comment) will work fine -- essentially calling Out of curiosity, one of my original questions remains open: does iOS ever call PlaybackService more than once? That is the current theory of why this bug happens, right? (i.e. specifically, this issue was thought to have happened only when you initiate |
Good question @fivecar. I'm going to add a "Breadcrumb" to my playback service register so I can check that fact in Bugsnag reports. Having said that - since I upgraded to I'm running V4 RC in production for almost 2 weeks now and it seems all good so far. |
Great to hear. I'm a bit hesitant to upgrade to ^4.0.0 because I've patched a variety of issues to get RNTrackPlayer (and SwiftAudioEx) working, only some of the PRs of which the maintainers have agreed to take, and so I don't have the time right now to re-test and re-regress/port/patch the fixes they didn't take. But at some point, it'd be great to be able to move forward, especially with the types of timing-related hard-to-reproduce issues that arise at the architecture level. |
@brad-sf @fivecar @pabloromeu have you guys seen this issue recently? For me since we started using v3 it's appearing and it never went away. We have just updated from v3.2.0 to v4.0.0-rc06 and the issue seems to have increased a little bit. Do you guys have any idea for me or what I could be doing wrong? We call setup player like this |
@marcvictorpassarelli : I upgraded my app to RC6, and am still seeing this crash. (@brad-sf -- just confirming that I've indeed seen this crash even beyond the RC4 you mentioned above). I'm initializing the app exactly as the docs recommend (and in fact IIRC I updated the docs a bit, even). |
@fivecar I think in our app we're doing as it should too, only calling |
@fivecar @marcvictorpassarelli please upgrade to the latest RC. You're likely not going to get a ton of help unless you're running the latest version. |
I am also seeing this crash in production – will spend some time to fix it in the coming days. |
Thanks for the tracelog! That really pinpoints the place. So here’s where we add a metadata listener to a media item here which we remove here. I guess in some cases it tries to add the output before it’s been removed and because we only create one metadata output object that gets shared it fails. It shouldn’t because we make sure to call |
Maybe better would not be to rely on those variables and see if we can just check if there are listeners/output to be removed and remove them. |
It could also be some kind of race condition caused by |
Managed to reproduce in a unit test and made a fix in SwiftAudioEx. That'll be merged in RNTP via #2176 and will go out with v4 of the library. |
Since I updated RNTP to 4.0.1 in my project I see increased amount of crashes:
|
Why revert the I hava tried the Steps To Reproduce: Calling TrackPlayer.next() time after time 2023-12-02 14:04:43.381818+0800 SFM[34322:7216160] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVPlayerItem addOutput:] Cannot attach an output that is already attached or nil output'
*** First throw call stack:
<_NSCallStackArray 0x280af87e0> [
7619939508,
7503152080,
7881000876,
4363523192,
4346587964,
4411678776,
4411691444,
4411784752,
4411745784,
4411744988,
7620525096,
7620400480,
7620420588,
8615609180,
7657697112,
7657696188,
4343907612,
8145964524
]
libc++abi: terminating due to uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVPlayerItem addOutput:] Cannot attach an output that is already attached or nil output'
terminating due to uncaught exception of type NSException |
I'm on v4.0.1 and am getting this crash in production. Should we reactivate this issue so that it's tracked, and close it once doublesymmetry/SwiftAudioEx#74 gets into a release of RNTP? |
Ok - someone else continued this discussion in #2230 . |
This issue is also affecting my app, I hope it gets fixed soon |
Describe the Bug
I am getting some kind of error on SwiftAudioEx.
Steps To Reproduce
TBH it did not happen to me on debug, but it seems that is happening to my users in production. I have reports from Firebase Crashlytics.
Environment Info:
Using react-native-track-player@^3.2.0
This happens on real devices, most of them on iOS 15.
How can you help
I have seen a PR on SwiftAudioEx that might fix this: doublesymmetry/SwiftAudioEx#30
The text was updated successfully, but these errors were encountered: