Skip to content

Commit

Permalink
Merge pull request #243 from THEOplayer/bugfix/android14
Browse files Browse the repository at this point in the history
Bugfix/android14
  • Loading branch information
tvanlaerhoven authored Dec 20, 2023
2 parents 201b49b + 402a62f commit b769e88
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 30 deletions.
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.

- Changed the Android notification channel name to `Notification channel`. It can be renamed by defining the `notification_channel_name` resource string.

### Added

- Added support for Android 14.

## [3.3.2] - 23-12-12

### Fixed
Expand Down
10 changes: 5 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.21'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21'
}
}

Expand All @@ -29,11 +29,11 @@ def enabledCast = safeExtGet("THEOplayer_extensionCast", 'false').toBoolean()
def enabledMediaSession = safeExtGet("THEOplayer_extensionMediaSession", 'true').toBoolean()

android {
compileSdk safeExtGet('THEOplayer_compileSdkVersion', 33)
compileSdk safeExtGet('THEOplayer_compileSdkVersion', 34)

defaultConfig {
minSdkVersion safeExtGet('THEOplayer_minSdkVersion', 21)
targetSdkVersion safeExtGet('THEOplayer_targetSdkVersion', 33)
targetSdkVersion safeExtGet('THEOplayer_targetSdkVersion', 34)
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -101,7 +101,7 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
implementation "androidx.appcompat:appcompat:1.6.1"

// The minimum supported THEOplayer version is 6.0.0
Expand Down
9 changes: 9 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
-->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<!--
Allows a regular application to use Service.startForeground with the type "mediaPlayback".
Protection level: normal|instant
Apps that target Android 14 and use a foreground service must declare a specific
permission, based on the foreground service type that Android 14 introduces.
-->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />

<application>

<!-- Allow background audio playback by registering this service. -->
Expand Down
19 changes: 15 additions & 4 deletions android/src/main/java/com/theoplayer/presentation/PipUtils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theoplayer.presentation

import android.annotation.SuppressLint
import android.app.PendingIntent
import android.app.PictureInPictureParams
import android.app.RemoteAction
Expand Down Expand Up @@ -68,6 +69,7 @@ class PipUtils(
}
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
fun enable() {
if (enabled) {
return
Expand All @@ -78,10 +80,19 @@ class PipUtils(
adEvents.forEach { action ->
player.ads.addEventListener(action, onAdAction)
}
reactContext.currentActivity?.registerReceiver(
broadcastReceiver,
IntentFilter(ACTION_MEDIA_CONTROL)
)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
reactContext.currentActivity?.registerReceiver(
broadcastReceiver,
IntentFilter(ACTION_MEDIA_CONTROL), Context.RECEIVER_EXPORTED
)
} else {
reactContext.currentActivity?.registerReceiver(
broadcastReceiver,
IntentFilter(ACTION_MEDIA_CONTROL)
)
}

enabled = true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theoplayer.presentation

import android.annotation.SuppressLint
import android.app.AppOpsManager
import android.content.BroadcastReceiver
import android.content.Context
Expand All @@ -18,6 +19,7 @@ import com.theoplayer.android.api.error.ErrorCode
import com.theoplayer.android.api.error.THEOplayerException
import com.theoplayer.android.api.player.PresentationMode

@SuppressLint("UnspecifiedRegisterReceiverFlag")
class PresentationManager(
private val viewCtx: ReactTHEOplayerContext,
private val reactContext: ThemedReactContext,
Expand Down Expand Up @@ -58,12 +60,27 @@ class PresentationManager(
supportsPip =
reactContext.packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
}
reactContext.currentActivity?.registerReceiver(
onUserLeaveHintReceiver, IntentFilter("onUserLeaveHint")
)
reactContext.currentActivity?.registerReceiver(
onPictureInPictureModeChanged, IntentFilter("onPictureInPictureModeChanged")
)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
reactContext.currentActivity?.registerReceiver(
onUserLeaveHintReceiver, IntentFilter("onUserLeaveHint"), Context.RECEIVER_EXPORTED
)
} else {
reactContext.currentActivity?.registerReceiver(
onUserLeaveHintReceiver, IntentFilter("onUserLeaveHint")
)
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
reactContext.currentActivity?.registerReceiver(
onPictureInPictureModeChanged, IntentFilter("onPictureInPictureModeChanged"),
Context.RECEIVER_EXPORTED
)
} else {
reactContext.currentActivity?.registerReceiver(
onPictureInPictureModeChanged, IntentFilter("onPictureInPictureModeChanged")
)
}
}

fun destroy() {
Expand Down
7 changes: 3 additions & 4 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,15 @@ android {
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation project(path: ':reactnativetheoplayer')
implementation "com.google.android.gms:play-services-cast-framework:${safeExtGet('castFrameworkVersion', '+')}"

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
debugImplementation("com.facebook.flipper:flipper:0.242.0")
debugImplementation("com.facebook.flipper:flipper-network-plugin:0.242.0") {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:0.182.0")
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import android.content.Intent;
import android.content.res.Configuration;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.NonNull;

import com.facebook.react.ReactActivity;
import com.google.android.gms.cast.framework.CastContext;

Expand Down Expand Up @@ -40,8 +43,10 @@ public void onUserLeaveHint () {
}

@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, @NonNull Configuration newConfig) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
}
Intent intent = new Intent("onPictureInPictureModeChanged");
intent.putExtra("isInPictureInPictureMode", isInPictureInPictureMode);
this.sendBroadcast(intent);
Expand Down
12 changes: 6 additions & 6 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

buildscript {
ext {
buildToolsVersion = "30.0.3"
buildToolsVersion = "34.0.0"
minSdkVersion = 24
compileSdkVersion = 33
targetSdkVersion = 33
compileSdkVersion = 34
targetSdkVersion = 34
ndkVersion = "23.1.7779620"
castFrameworkVersion = "21.0.1"
castFrameworkVersion = "21.4.0"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
classpath("com.android.tools.build:gradle:7.4.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21")
classpath("com.facebook.react:react-native-gradle-plugin")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
3 changes: 0 additions & 3 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.142.0

# Use this property to specify which architecture you want to build.
# You can also override it from the CLI using
# ./gradlew <task> -PreactNativeArchitectures=x86_64
Expand Down

0 comments on commit b769e88

Please sign in to comment.