SDK 45 BETA-8 [android][expo-av] - Crash randomly when un-mounting or pausing/unloading videos
See original GitHub issueSummary
Related: https://github.com/expo/expo/pull/16611
This PR did not fix the issue unfortunately. It never happened to me on expo-av 11.1.0 though, only after the upgrade to Expo SDK 45
Your app just crashed. See the error below.
java.lang.IllegalStateException: Player is accessed on the wrong thread. See https://exoplayer.dev/issues/player-accessed-on-wrong-thread
at com.google.android.exoplayer2.SimpleExoPlayer.verifyApplicationThread(SimpleExoPlayer.java:1953)
at com.google.android.exoplayer2.SimpleExoPlayer.setPlayWhenReady(SimpleExoPlayer.java:1466)
at expo.modules.av.player.SimpleExoPlayerData.pauseImmediately(SimpleExoPlayerData.java:247)
at expo.modules.av.player.PlayerData.onPause(PlayerData.java:477)
at expo.modules.av.video.VideoView.onPause(VideoView.java:521)
at expo.modules.av.AVManager.lambda$onHostPause$2$expo-modules-av-AVManager(AVManager.java:236)
at expo.modules.av.AVManager$$ExternalSyntheticLambda2.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:914)
at android.os.Handler.dispatchMessage(Handler.java:100)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:224)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
at java.lang.Thread.run(Thread.java:919)
Managed or bare workflow? If you have ios/
or android/
directories in your project, the answer is bare!
bare
What platform(s) does this occur on?
Android
SDK Version (managed workflow only)
SDK 45-beta-8
Environment
expo-env-info 1.0.3 environment info:
System:
OS: macOS 12.3.1
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.19.1 - /usr/local/opt/node@14/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 6.14.16 - /usr/local/opt/node@14/bin/npm
Managers:
CocoaPods: 1.11.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
IDEs:
Android Studio: 4.1 AI-201.8743.12.41.6953283
Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
npmGlobalPackages:
eas-cli: 0.51.0
expo-cli: 5.4.2
Expo Workflow: bare
Reproducible demo
This happens pretty randomly, therefore no MCVE. I try to provide quick issues.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It appears for Video SimpleExoPlayerData.load is getting called on the main thread (I tried via props and loadAsync). But Audio via
Audio.Sound.createAsync
is on the native module thread.I think the previous PR will have fixed it for Audio but broken Video.
To fix it I think we need to decide which is the correct thread to interactive with it from, as far as I can see from the docs ExoPlayer handles its own threading so it doesn’t really matter which we use as long as its consistent.
I think making sure it uses the main thread is the simplest as the previous PR can be reverted.
It’s also an opportunity to fix: https://github.com/expo/expo/blob/5e13e1e137060e3dc61bf3a6274488f390bf587f/packages/expo-av/android/src/main/java/expo/modules/av/player/SimpleExoPlayerData.java#L129-L133
The tricky bit will be ensuring every interaction with the player is on the correct thread.
@mnightingale I can confirm that your PR did fully fix the issue for me. I could not reproduce it anymore.