Skip to content

Commit 26f0d4c

Browse files
committed
-Full Screen Flickering Bug Fixed
1 parent e6e90fe commit 26f0d4c

File tree

3 files changed

+52
-70
lines changed

3 files changed

+52
-70
lines changed

gradle/libs.versions.toml

+9-13
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,31 @@
22
agp = "8.2.2"
33
kotlin = "2.0.0"
44
kotlinxSerializationJsonVersion = "1.7.1"
5-
media3ExoplayerVersion = "1.4.1"
6-
media3ExoplayerDashVersion = "1.4.1"
75
nexus-publish = "2.0.0-rc-1"
86
android-minSdk = "24"
97
android-compileSdk = "34"
10-
startupRuntime = "1.1.1"
11-
media3Ui = "1.4.0"
12-
media3ExoplayerDash = "1.4.0"
13-
media3Exoplayer = "1.4.0"
8+
startupRuntime = "1.2.0"
9+
media3Exoplayer = "1.4.1"
1410
core = "12.1.0"
1511
compose = "1.6.11"
1612
androidx-appcompat = "1.7.0"
17-
androidx-activityCompose = "1.9.1"
18-
compose-uitooling = "1.6.8"
13+
androidx-activityCompose = "1.9.2"
14+
compose-uitooling = "1.7.3"
1915
kotlinx-coroutines = "1.9.0-RC"
2016

2117

2218

2319
[libraries]
24-
androidx-media3-exoplayer-dash-v141 = { module = "androidx.media3:media3-exoplayer-dash", version.ref = "media3ExoplayerDashVersion" }
25-
androidx-media3-exoplayer-v141 = { module = "androidx.media3:media3-exoplayer", version.ref = "media3ExoplayerVersion" }
26-
androidx-media3-session = { module = "androidx.media3:media3-session", version.ref = "media3Ui" }
20+
androidx-media3-exoplayer-dash-v141 = { module = "androidx.media3:media3-exoplayer-dash", version.ref = "media3Exoplayer" }
21+
androidx-media3-exoplayer-v141 = { module = "androidx.media3:media3-exoplayer", version.ref = "media3Exoplayer" }
22+
androidx-media3-session = { module = "androidx.media3:media3-session", version.ref = "media3Exoplayer" }
2723
jetbrains-kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJsonVersion" }
2824
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
2925
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinxSerializationJsonVersion" }
3026
nexus-publish = { module = "io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin", version.ref = "nexus-publish" }
3127
startup-runtime = { module = "androidx.startup:startup-runtime", version.ref = "startupRuntime" }
32-
androidx-media3-ui = { module = "androidx.media3:media3-ui", version.ref = "media3Ui" }
33-
androidx-media3-exoplayer-dash = { module = "androidx.media3:media3-exoplayer-dash", version.ref = "media3ExoplayerDash" }
28+
androidx-media3-ui = { module = "androidx.media3:media3-ui", version.ref = "media3Exoplayer" }
29+
androidx-media3-exoplayer-dash = { module = "androidx.media3:media3-exoplayer-dash", version.ref = "media3Exoplayer" }
3430
androidx-media3-exoplayer = { module = "androidx.media3:media3-exoplayer", version.ref = "media3Exoplayer" }
3531
custom-ui = { module = "com.pierfrancescosoffritti.androidyoutubeplayer:custom-ui", version.ref = "core" }
3632
core = { module = "com.pierfrancescosoffritti.androidyoutubeplayer:core", version.ref = "core" }

mediaplayer-kmp/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ mavenPublishing {
104104
coordinates(
105105
groupId = "io.github.khubaibkhan4",
106106
artifactId = "mediaplayer-kmp",
107-
version = "1.1.8"
107+
version = "1.1.9"
108108
)
109109

110110
pom {

mediaplayer-kmp/src/androidMain/kotlin/YouTubePlayer.android.kt

+42-56
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import android.annotation.SuppressLint
22
import android.content.pm.ActivityInfo
33
import android.os.Build
4+
import android.os.Handler
5+
import android.os.Looper
46
import android.view.View
57
import android.view.ViewGroup
68
import android.view.WindowInsets
@@ -202,7 +204,6 @@ fun YoutubeVideoPlayer(
202204
val playerFragment = YouTubePlayerView(mContext)
203205
var isFullScreen by remember { mutableStateOf(false) }
204206

205-
206207
val playerStateListener = object : AbstractYouTubePlayerListener() {
207208
override fun onReady(youTubePlayer: com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer) {
208209
super.onReady(youTubePlayer)
@@ -214,35 +215,23 @@ fun YoutubeVideoPlayer(
214215
youTubePlayer: com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer,
215216
state: PlayerConstants.PlayerState,
216217
) {
217-
super.onStateChange(youTubePlayer, state)
218218
when (state) {
219219
PlayerConstants.PlayerState.BUFFERING -> {
220220
isLoading.invoke(true)
221221
isPlaying.invoke(false)
222222
}
223-
224223
PlayerConstants.PlayerState.PLAYING -> {
225224
isLoading.invoke(false)
226225
isPlaying.invoke(true)
227226
}
228-
229227
PlayerConstants.PlayerState.ENDED -> {
230228
isPlaying.invoke(false)
231229
isLoading.invoke(false)
232230
onVideoEnded.invoke()
233231
}
234-
235232
else -> {}
236233
}
237234
}
238-
239-
override fun onError(
240-
youTubePlayer: com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer,
241-
error: PlayerConstants.PlayerError,
242-
) {
243-
super.onError(youTubePlayer, error)
244-
println("iFramePlayer Error Reason = $error")
245-
}
246235
}
247236

248237
var fullscreenView: View? by remember { mutableStateOf(null) }
@@ -252,31 +241,34 @@ fun YoutubeVideoPlayer(
252241
isFullScreen = true
253242
fullscreenView = view
254243
playerFragment.visibility = View.GONE
244+
255245
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
256246

257-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
258-
activity.window.setDecorFitsSystemWindows(false)
259-
activity.window.insetsController?.apply {
260-
hide(WindowInsets.Type.systemBars())
261-
systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
247+
Handler(Looper.getMainLooper()).post {
248+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
249+
activity.window.setDecorFitsSystemWindows(false)
250+
activity.window.insetsController?.apply {
251+
hide(WindowInsets.Type.systemBars())
252+
systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
253+
}
254+
} else {
255+
@Suppress("DEPRECATION")
256+
activity.window.setFlags(
257+
WindowManager.LayoutParams.FLAG_FULLSCREEN,
258+
WindowManager.LayoutParams.FLAG_FULLSCREEN
259+
)
260+
activity.window.decorView.systemUiVisibility =
261+
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
262+
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
263+
View.SYSTEM_UI_FLAG_FULLSCREEN
262264
}
263-
} else {
264-
@Suppress("DEPRECATION")
265-
activity.window.setFlags(
266-
WindowManager.LayoutParams.FLAG_FULLSCREEN,
267-
WindowManager.LayoutParams.FLAG_FULLSCREEN
268-
)
269-
activity.window.decorView.systemUiVisibility =
270-
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
271-
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
272-
View.SYSTEM_UI_FLAG_FULLSCREEN
273-
}
274265

275-
(activity.window.decorView as ViewGroup).apply {
276-
addView(view)
266+
(activity.window.decorView as ViewGroup).apply {
267+
addView(view)
268+
}
277269
}
278270

279-
player?.play()
271+
player?.play() // Start playing video after UI updates
280272
}
281273

282274
override fun onExitFullscreen() {
@@ -285,24 +277,26 @@ fun YoutubeVideoPlayer(
285277

286278
playerFragment.visibility = View.VISIBLE
287279

288-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
289-
activity.window.setDecorFitsSystemWindows(true)
290-
activity.window.insetsController?.apply {
291-
show(WindowInsets.Type.systemBars())
280+
Handler(Looper.getMainLooper()).post {
281+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
282+
activity.window.setDecorFitsSystemWindows(true)
283+
activity.window.insetsController?.apply {
284+
show(WindowInsets.Type.systemBars())
285+
}
286+
} else {
287+
@Suppress("DEPRECATION")
288+
activity.window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
289+
activity.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
292290
}
293-
} else {
294-
@Suppress("DEPRECATION")
295-
activity.window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
296-
activity.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
297-
}
298291

299-
fullscreenView?.let { view ->
300-
(activity.window.decorView as ViewGroup).apply {
301-
removeView(view)
292+
fullscreenView?.let { view ->
293+
(activity.window.decorView as ViewGroup).apply {
294+
removeView(view)
295+
}
302296
}
303297
}
304298

305-
player?.play()
299+
player?.play() // Resume playing video after UI changes
306300
}
307301
}
308302

@@ -345,17 +339,9 @@ fun YoutubeVideoPlayer(
345339
val lifecycle = mLifeCycleOwner.lifecycle
346340
val observer = LifecycleEventObserver { _, event ->
347341
when (event) {
348-
Lifecycle.Event.ON_RESUME -> {
349-
player?.play()
350-
}
351-
352-
Lifecycle.Event.ON_PAUSE -> {
353-
player?.pause()
354-
}
355-
356-
else -> {
357-
//
358-
}
342+
Lifecycle.Event.ON_RESUME -> player?.play()
343+
Lifecycle.Event.ON_PAUSE -> player?.pause()
344+
else -> {}
359345
}
360346
}
361347
lifecycle.addObserver(observer)

0 commit comments

Comments
 (0)