Skip to content

Commit f96d4e3

Browse files
authored
[android][video] Avoid crash when FullscreenPlayerActivity init fails (#42943)
This indicates that the error path inside `onCreate` calls `finish()` while `videoViewId` is still uninitialized. Crash Log ``` Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{hoge/expo.modules.video.FullscreenPlayerActivity}: kotlin.UninitializedPropertyAccessException: lateinit property videoViewId has not been initialized ``` # How - Made `videoViewId` nullable and guarded its use in `finish()` to avoid `UninitializedPropertyAccessException`. - Made `orientationHelper` nullable and guarded lifecycle calls to avoid similar issues if initialization fails early. # Test Plan - passed CI # Checklist - [x] I added a `changelog.md` entry and rebuilt the package sources according to [this short guide](https://github.com/expo/expo/blob/main/CONTRIBUTING.md#-before-submitting) - [x] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). - [x] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
1 parent a894fa3 commit f96d4e3

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎packages/expo-video/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
- [iOS] Prevents blocking main thread when loading asset tracks for non-HSL tracks ([#42037](https://github.com/expo/expo/pull/42037) by [@santitopo](https://github.com/santitopo))
3939
- [Android] Fix crash due to `SimpleCache` directory lock conflicts. ([#42723](https://github.com/expo/expo/pull/42723) by [@santitopo](https://github.com/santitopo))
40+
- [Android] Avoid crash when FullscreenPlayerActivity init fails. ([#42943](https://github.com/expo/expo/pull/42943) by [@amyu](https://github.com/amyu))
4041

4142
## 55.0.4 — 2026-02-03
4243

‎packages/expo-video/android/src/main/java/expo/modules/video/FullscreenPlayerActivity.kt‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ import expo.modules.video.managers.VideoManager
2727
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
2828
class FullscreenPlayerActivity : Activity() {
2929
private lateinit var mContentView: View
30-
private lateinit var videoViewId: String
30+
private var videoViewId: String? = null
3131
private var videoPlayer: VideoPlayer? = null
3232
private lateinit var playerView: PlayerView
3333
private lateinit var videoView: VideoView
3434
private var didFinish = false
3535
private var wasAutoPaused = false
3636
private lateinit var options: FullscreenOptions
37-
private lateinit var orientationHelper: FullscreenActivityOrientationHelper
37+
private var orientationHelper: FullscreenActivityOrientationHelper? = null
3838
private var captioningChangeListener: CaptioningManager.CaptioningChangeListener? = null
3939

4040
override fun onCreate(savedInstanceState: Bundle?) {
@@ -53,7 +53,8 @@ class FullscreenPlayerActivity : Activity() {
5353
?: throw FullScreenOptionsNotFoundException()
5454
}
5555

56-
videoView = VideoManager.getVideoView(videoViewId)
56+
videoView = videoViewId?.let { VideoManager.getVideoView(it) }
57+
?: throw FullScreenVideoViewNotFoundException()
5758

5859
orientationHelper = FullscreenActivityOrientationHelper(
5960
this,
@@ -65,7 +66,7 @@ class FullscreenPlayerActivity : Activity() {
6566
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6667
}
6768
)
68-
orientationHelper.startOrientationEventListener()
69+
orientationHelper?.startOrientationEventListener()
6970
} catch (e: CodedException) {
7071
Log.e("ExpoVideo", "${e.message}", e)
7172
finish()
@@ -119,7 +120,7 @@ class FullscreenPlayerActivity : Activity() {
119120
override fun finish() {
120121
super.finish()
121122
didFinish = true
122-
VideoManager.getVideoView(videoViewId).attachPlayer()
123+
videoViewId?.let { VideoManager.getVideoView(it).attachPlayer() }
123124

124125
// Disable the exit transition
125126
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
@@ -131,7 +132,7 @@ class FullscreenPlayerActivity : Activity() {
131132
}
132133

133134
override fun onResume() {
134-
orientationHelper.startOrientationEventListener()
135+
orientationHelper?.startOrientationEventListener()
135136
playerView.useController = true
136137
// Reconfigure subtitles when resuming (handles returning from settings)
137138
SubtitleUtils.configureSubtitleView(playerView, this)
@@ -146,7 +147,7 @@ class FullscreenPlayerActivity : Activity() {
146147
videoPlayer?.player?.pause()
147148
}
148149
}
149-
orientationHelper.stopOrientationEventListener()
150+
orientationHelper?.stopOrientationEventListener()
150151
super.onPause()
151152
}
152153

@@ -162,7 +163,7 @@ class FullscreenPlayerActivity : Activity() {
162163

163164
videoView.exitFullscreen()
164165
VideoManager.unregisterFullscreenPlayerActivity(hashCode().toString())
165-
orientationHelper.stopOrientationEventListener()
166+
orientationHelper?.stopOrientationEventListener()
166167
}
167168

168169
private fun setupFullscreenButton() {
@@ -216,7 +217,7 @@ class FullscreenPlayerActivity : Activity() {
216217

217218
override fun onConfigurationChanged(newConfig: Configuration) {
218219
super.onConfigurationChanged(newConfig)
219-
orientationHelper.onConfigurationChanged(newConfig)
220+
orientationHelper?.onConfigurationChanged(newConfig)
220221
}
221222

222223
companion object {

0 commit comments

Comments
 (0)