react-native-track-player: [AVPlayerItem addOutput:] Cannot attach an output that is already attached.
Describe the Bug I am getting some kind of error on SwiftAudioEx.
[AVPlayerItem addOutput:] Cannot attach an output that is already attached.
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:
System:
OS: macOS 13.0
CPU: (8) arm64 Apple M1
Memory: 137.73 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.11.0 - /usr/local/bin/node
Yarn: 1.23.0-20220130.1630 - /usr/local/bin/yarn
npm: 8.19.2 - /opt/homebrew/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/lib/ruby/gems/3.0.0/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK:
API Levels: 23, 26, 27, 28, 29, 30, 31, 33
Build Tools: 27.0.3, 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0
System Images: android-28 | Google Play Intel x86 Atom, android-30 | Google APIs ARM 64 v8a, android-30 | Google Play ARM 64 v8a
Android NDK: 21.0.6113669
IDEs:
Android Studio: Dolphin 2021.3.1 Patch 1 Dolphin 2021.3.1 Patch 1
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_241 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.0.0 => 18.0.0
react-native: 0.69.6 => 0.69.6
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
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: https://github.com/doublesymmetry/SwiftAudioEx/pull/30
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 47 (11 by maintainers)
I am also seeing this crash in production – will spend some time to fix it in the coming days.
I’m getting this in production, with (what I think is) only a singleton TrackPlayer. Specifically:
TrackPlayer.registerPlaybackService(() => PlaybackService)only in index.js at the root of my app, right afterAppRegistry.registerComponent(appName, () => App), according to the docs.PlaybackServicecallsawait setupPlayeras its first action, since the rest of the service requires TrackPlayer.Can the playback service be called by iOS multiple times during the same app lifetime? Because if so, I can see how
setupPlayerwould be called multiple times (in that case).But if so, what’s the right order in which to instantiate both the playback service (which almost definitely uses TrackPlayer) and to call
setupPlayer? The docs say thatsetupPlayerneeds to be called before any TrackPlayer functions; and yet it also says that you need to register the playback service immediately afterAppRegistry.registerComponent. Should you end up with something like this in your index.js?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 https://github.com/doublesymmetry/SwiftAudioEx/pull/74 gets into a release of RNTP?
Since I updated RNTP to 4.0.1 in my project I see increased amount of crashes:
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.
@fivecar setup the player as soon as possible