Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/media3 #447

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Fixed a memory leak on iOS, caused by the wrapping ViewController that was keeping a strong reference to the THEOplayerRCTView.

### Added

- Added support for the experimental media3 player pipeline on Android.

### Changed

- **BREAKING**: Changed the `view` parameter in the `Omid` API from a ref container to a native node handle when registering "friendly" obstructions.
Expand Down
16 changes: 14 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def enabledTHEOads = safeExtGet("THEOplayer_extensionTHEOads", 'false').toBoolea
def enabledAds = enabledGoogleIMA || enabledGoogleDAI || enabledTHEOads
def enabledCast = safeExtGet("THEOplayer_extensionCast", 'false').toBoolean()
def enabledMediaSession = safeExtGet("THEOplayer_extensionMediaSession", 'true').toBoolean()
def enabledMedia3 = safeExtGet("THEOplayer_extensionMedia3", 'true').toBoolean()

android {
compileSdk safeExtGet('THEOplayer_compileSdkVersion', 34)
Expand Down Expand Up @@ -66,6 +67,7 @@ android {
buildConfigField "boolean", "EXTENSION_ADS", "${enabledAds}"
buildConfigField "boolean", "EXTENSION_CAST", "${enabledCast}"
buildConfigField "boolean", "EXTENSION_MEDIASESSION", "${enabledMediaSession}"
buildConfigField "boolean", "EXTENSION_MEDIA3", "${enabledMedia3}"

consumerProguardFiles 'proguard-rules.pro'
}
Expand Down Expand Up @@ -93,7 +95,9 @@ android {

rootProject.allprojects {
repositories {
mavenLocal()
maven { url "https://maven.theoplayer.com/releases" }
maven { url "https://maven.theoplayer.com/snapshots" }
maven { url("$rootDir/../node_modules/react-native-theoplayer/android/local") }
}
}
Expand All @@ -110,8 +114,8 @@ repositories {
maven { url "https://maven.theoplayer.com/releases" }
}

// The minimum supported THEOplayer version is 8.3.0
def theoplayer_sdk_version = safeExtGet('THEOplayer_sdk', '[8.3.0, 9.0.0)')
// The minimum supported THEOplayer version is 8.5.0
def theoplayer_sdk_version = safeExtGet('THEOplayer_sdk', '[8.5.0, 9.0.0)')
def theoplayer_mediasession_version = safeExtGet('THEOplayer_mediasession', '[8.0.0, 9.0.0)')

dependencies {
Expand Down Expand Up @@ -158,6 +162,14 @@ dependencies {
println('Disable THEOplayer cast extension.')
compileOnly "com.theoplayer.theoplayer-sdk-android:integration-cast:${theoplayer_sdk_version}"
}

if (enabledMedia3) {
println('Enable THEOplayer media3 extension.')
implementation "com.theoplayer.theoplayer-sdk-android:integration-media3:${theoplayer_sdk_version}"
} else {
println('Disable THEOplayer media3 extension.')
compileOnly "com.theoplayer.theoplayer-sdk-android:integration-media3:${theoplayer_sdk_version}"
}
}

// Make sure to align all ads extension versions
Expand Down
10 changes: 10 additions & 0 deletions android/src/main/java/com/theoplayer/PlayerConfigAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private const val PROP_UI_ENABLED = "uiEnabled"
private const val PROP_CAST_STRATEGY = "strategy"
private const val PROP_RETRY_CONFIG = "retryConfiguration"
private const val PROP_HLS_DATE_RANGE = "hlsDateRange"
private const val PROP_USE_MEDIA3 = "useMedia3"
private const val PROP_RETRY_MAX_RETRIES = "maxRetries"
private const val PROP_RETRY_MIN_BACKOFF = "minimumBackoff"
private const val PROP_RETRY_MAX_BACKOFF = "maximumBackoff"
Expand All @@ -39,6 +40,12 @@ private const val PROP_ALLOWED_MIMETYPES = "allowedMimeTypes"

class PlayerConfigAdapter(private val configProps: ReadableMap?) {

/**
* Whether the Media3 extension is used for play-out.
*/
var useMedia3: Boolean = false
private set

/**
* Get general THEOplayerConfig object; these properties apply:
* - license: The license for the player.
Expand All @@ -63,6 +70,9 @@ class PlayerConfigAdapter(private val configProps: ReadableMap?) {
if (hasKey(PROP_HLS_DATE_RANGE)) {
hlsDateRange(getBoolean(PROP_HLS_DATE_RANGE))
}
if (hasKey(PROP_USE_MEDIA3)) {
useMedia3 = getBoolean(PROP_USE_MEDIA3)
}
pipConfiguration(PipConfiguration.Builder().build())
}
}.build()
Expand Down
21 changes: 21 additions & 0 deletions android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import com.theoplayer.android.api.cast.CastIntegration
import com.theoplayer.android.api.cast.CastIntegrationFactory
import com.theoplayer.android.api.event.EventListener
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.connector.mediasession.MediaSessionConnector
import com.theoplayer.audio.AudioBecomingNoisyManager
Expand Down Expand Up @@ -84,6 +86,8 @@ class ReactTHEOplayerContext private constructor(
var imaIntegration: GoogleImaIntegration? = null
private var theoAdsIntegration: TheoAdsIntegration? = null
var castIntegration: CastIntegration? = null
@Suppress("UnstableApiUsage")
private var media3Integration: Media3PlayerIntegration? = null
var wasPlayingOnHostPause: Boolean = false
private var isHostPaused: Boolean = false

Expand Down Expand Up @@ -321,6 +325,23 @@ class ReactTHEOplayerContext private constructor(
} catch (e: Exception) {
Log.w(TAG, "Failed to configure Cast integration ${e.message}")
}
try {
if (BuildConfig.EXTENSION_MEDIA3) {
@Suppress("UnstableApiUsage")
media3Integration =
Media3PlayerIntegrationFactory.createMedia3PlayerIntegration { _, _ ->
// selectedSource -> represents the TypedSource the player picked to play.
// source -> represents the SourceDescription passed to the player.
// return true -> the Media3 integration pipeline will be used to play the selected source.
// return false -> the default pipeline will be used to play the selected source.
configAdapter.useMedia3
}
playerView.player.addIntegration(media3Integration)
}
} catch (e: Exception) {
Log.w(TAG, "Failed to configure Cast integration ${e.message}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably log something like "Failed to configure Media3 integration ${e.message}" instead?

}

// Add other future integrations here.
}

Expand Down
3 changes: 2 additions & 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.3.0, 9.0.0)
#THEOplayer_sdk=[8.5.0, 9.0.0)

# Override Android sdk versions
#THEOplayer_compileSdkVersion = 34
Expand All @@ -63,6 +63,7 @@ THEOplayer_extensionGoogleDAI = true
THEOplayer_extensionCast = true
THEOplayer_extensionTHEOads = true
THEOplayer_extensionMediaSession = true
THEOplayer_extensionMedia3 = true

# Optionally limit timeUpdate rate, which could improve performance.
# Possible values: (default: UNLIMITED)
Expand Down
11 changes: 11 additions & 0 deletions src/api/config/PlayerConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ export interface PlayerConfiguration {
* <br/> - This parameter only applies to Web and Android platforms.
*/
liveOffset?: number;

/**
* Sets whether the Media3 extension is used for play-out on Android.
*
* @experimental
* @remarks
* <br/> - This parameter only applies to Android platforms.
*
* @defaultValue `false`.
*/
useMedia3?: boolean;
}

/**
Expand Down
Loading