From 1ffdef454d8e1ae09b6472f2f103aac9ef61b40a Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Wed, 27 Nov 2024 11:57:59 +0100 Subject: [PATCH 1/3] Add support for SURFACE_CONTROL RenderingTarget --- .../com/theoplayer/ReactTHEOplayerContext.kt | 9 ++++ .../com/theoplayer/player/PlayerModule.kt | 42 ++++++++++++------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt b/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt index 9e29bb868..e8bdd9dfd 100644 --- a/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt +++ b/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt @@ -6,6 +6,7 @@ import android.content.Context import android.content.Intent import android.content.ServiceConnection import android.content.res.Configuration +import android.os.Build import android.os.Handler import android.os.IBinder import android.os.Looper @@ -27,6 +28,7 @@ import com.theoplayer.android.api.event.player.* import com.theoplayer.android.api.media3.Media3PlayerIntegration import com.theoplayer.android.api.media3.Media3PlayerIntegrationFactory import com.theoplayer.android.api.player.Player +import com.theoplayer.android.api.player.RenderingTarget import com.theoplayer.android.connector.mediasession.MediaSessionConnector import com.theoplayer.audio.AudioBecomingNoisyManager import com.theoplayer.audio.AudioFocusManager @@ -220,6 +222,13 @@ class ReactTHEOplayerContext private constructor( } } + // By default, choose SURFACE_CONTROL/SURFACE_VIEW rendering target, based on API level. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + player.setRenderingTarget(RenderingTarget.SURFACE_CONTROL) + } else { + player.setRenderingTarget(RenderingTarget.SURFACE_VIEW) + } + // By default, the screen should remain on. playerView.keepScreenOn = true diff --git a/android/src/main/java/com/theoplayer/player/PlayerModule.kt b/android/src/main/java/com/theoplayer/player/PlayerModule.kt index 17ac0b527..b9b3771ac 100644 --- a/android/src/main/java/com/theoplayer/player/PlayerModule.kt +++ b/android/src/main/java/com/theoplayer/player/PlayerModule.kt @@ -1,5 +1,6 @@ package com.theoplayer.player +import android.os.Build import com.facebook.react.bridge.* import com.theoplayer.* import com.theoplayer.abr.ABRConfigurationAdapter @@ -184,11 +185,13 @@ class PlayerModule(context: ReactApplicationContext) : ReactContextBaseJavaModul @ReactMethod fun setPresentationMode(tag: Int, type: String?) { viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? -> - view?.presentationManager?.setPresentation(when (type) { - "picture-in-picture" -> PresentationMode.PICTURE_IN_PICTURE - "fullscreen" -> PresentationMode.FULLSCREEN - else -> PresentationMode.INLINE - }) + view?.presentationManager?.setPresentation( + when (type) { + "picture-in-picture" -> PresentationMode.PICTURE_IN_PICTURE + "fullscreen" -> PresentationMode.FULLSCREEN + else -> PresentationMode.INLINE + } + ) } } @@ -209,11 +212,13 @@ class PlayerModule(context: ReactApplicationContext) : ReactContextBaseJavaModul @ReactMethod fun setAspectRatio(tag: Int, ratio: String) { viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? -> - view?.player?.setAspectRatio(when (ratio) { - "fill" -> AspectRatio.FILL - "aspectFill" -> AspectRatio.ASPECT_FILL - else -> AspectRatio.FIT - }) + view?.player?.setAspectRatio( + when (ratio) { + "fill" -> AspectRatio.FILL + "aspectFill" -> AspectRatio.ASPECT_FILL + else -> AspectRatio.FIT + } + ) } } @@ -236,10 +241,19 @@ class PlayerModule(context: ReactApplicationContext) : ReactContextBaseJavaModul @ReactMethod fun setRenderingTarget(tag: Int, target: String) { viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? -> - view?.player?.setRenderingTarget(when (target) { - "textureView" -> RenderingTarget.TEXTURE_VIEW - else -> RenderingTarget.SURFACE_VIEW - }) + view?.player?.setRenderingTarget( + when (target) { + "textureView" -> RenderingTarget.TEXTURE_VIEW + else -> { + // Prefer SURFACE_CONTROL + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + RenderingTarget.SURFACE_CONTROL + } else { + RenderingTarget.SURFACE_VIEW + } + } + } + ) } } } From bb24ffe4b286dadd3a02bbd4c02d117a9292970f Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Wed, 27 Nov 2024 11:59:26 +0100 Subject: [PATCH 2/3] Update minimum native version --- android/build.gradle | 4 ++-- example/android/gradle.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 1baab076a..e9e176e2b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -114,8 +114,8 @@ repositories { maven { url "https://maven.theoplayer.com/releases" } } -// The minimum supported THEOplayer version is 8.5.0 -def theoplayer_sdk_version = safeExtGet('THEOplayer_sdk', '[8.5.0, 9.0.0)') +// The minimum supported THEOplayer version is 8.5.1 +def theoplayer_sdk_version = safeExtGet('THEOplayer_sdk', '[8.5.1, 9.0.0)') def theoplayer_mediasession_version = safeExtGet('THEOplayer_mediasession', '[8.0.0, 9.0.0)') dependencies { diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 3675dabe0..ebc5cac22 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -41,7 +41,7 @@ newArchEnabled=false hermesEnabled=true # Version of the THEOplayer SDK, if not specified, the latest available version within bounds is set. -#THEOplayer_sdk=[8.5.0, 9.0.0) +#THEOplayer_sdk=[8.5.1, 9.0.0) # Override Android sdk versions #THEOplayer_compileSdkVersion = 34 From 9af6f959f1590fa15a19794f76795690acb6a889 Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Wed, 27 Nov 2024 12:01:18 +0100 Subject: [PATCH 3/3] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03d95a7b9..95a684944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +- Added support for the `SURFACE_CONTROL` rendering target on Android, which improves switching from/to fullscreen presentation mode on API level 29+. + ### Fixed - Fixed a memory leak on iOS, caused by the wrapping ViewController that was keeping a strong reference to the THEOplayerRCTView.