Skip to content

Commit e645072

Browse files
authored
Fix: Picture picture in params crash on devices below Oreo (#1566)
2 parents a552467 + 1a90f4c commit e645072

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ android {
1616
minSdk = libs.versions.android.minSdk.get().toInt()
1717
targetSdk = libs.versions.android.targetSdk.get().toInt()
1818
applicationId = "dev.anilbeesetti.nextplayer"
19-
versionCode = 49
20-
versionName = "0.15.2"
19+
versionCode = 50
20+
versionName = "0.15.3"
2121
}
2222

2323
buildFeatures {

feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/state/PictureInPictureState.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,18 @@ class PictureInPictureState(
8484
var isInPictureInPictureMode: Boolean by mutableStateOf(false)
8585
private set
8686

87-
@RequiresApi(Build.VERSION_CODES.O)
88-
private val pictureInPictureParamsBuilder = PictureInPictureParams.Builder().apply {
89-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
90-
setSeamlessResizeEnabled(true)
87+
private val pictureInPictureParamsBuilder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
88+
PictureInPictureParams.Builder().apply {
89+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
90+
setSeamlessResizeEnabled(true)
91+
}
9192
}
93+
} else {
94+
null
9295
}
9396

9497
fun setVideoViewRect(rect: Rect) {
98+
if (pictureInPictureParamsBuilder == null) return
9599
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
96100
if (rect.width() <= 0 || rect.height() <= 0) return
97101

@@ -103,6 +107,7 @@ class PictureInPictureState(
103107
}
104108

105109
fun enterPictureInPictureMode(): Boolean {
110+
if (pictureInPictureParamsBuilder == null) return false
106111
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return false
107112
if (isInPictureInPictureMode) return false
108113

@@ -171,13 +176,15 @@ class PictureInPictureState(
171176
}
172177

173178
private fun updateAutoEnterEnabled() {
179+
if (pictureInPictureParamsBuilder == null) return
174180
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return
175181

176182
pictureInPictureParamsBuilder.setAutoEnterEnabled(autoEnter && player.isPlaying)
177183
activity.setPictureInPictureParams(pictureInPictureParamsBuilder.build())
178184
}
179185

180186
private fun updatePictureInPictureActions() {
187+
if (pictureInPictureParamsBuilder == null) return
181188
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
182189

183190
val actions = listOf(

0 commit comments

Comments
 (0)