Skip to content

Commit

Permalink
Merge pull request #451 from THEOplayer/feature/android_support_surfa…
Browse files Browse the repository at this point in the history
…ce_control

Feature/android support surface control
  • Loading branch information
tvanlaerhoven authored Nov 29, 2024
2 parents 54f67b4 + 9af6f95 commit c579c37
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
42 changes: 28 additions & 14 deletions android/src/main/java/com/theoplayer/player/PlayerModule.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
)
}
}

Expand All @@ -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
}
)
}
}

Expand All @@ -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
}
}
}
)
}
}
}
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c579c37

Please sign in to comment.