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

Release/v8.3.0 #405

Merged
merged 8 commits into from
Sep 30, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [8.3.0] - 24-09-30

### Added

- Added the option to specify the AVAudioSession mode for iOS (moviePlayback versus spokenAudio).

## [8.2.2] - 24-09-28

- Fixed a build issue on iOS for applications that run without the GOOGLE_IMA feature flag
Expand Down
18 changes: 14 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ repositories {
maven { url "https://maven.theoplayer.com/releases" }
}

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

dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
Expand All @@ -114,10 +118,6 @@ dependencies {
implementation "androidx.core:core-ktx:${safeExtGet('corektxVersion', '1.10.1')}"
implementation "com.google.code.gson:gson:2.11.0"

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

println("Using THEOplayer (${versionString(theoplayer_sdk_version)})")
implementation "com.theoplayer.theoplayer-sdk-android:core:${theoplayer_sdk_version}"
implementation "com.theoplayer.theoplayer-sdk-android:ads-wrapper:8.0.0"
Expand Down Expand Up @@ -151,3 +151,13 @@ dependencies {
compileOnly "com.theoplayer.theoplayer-sdk-android:integration-cast:${theoplayer_sdk_version}"
}
}

// Make sure to align all ads extension versions
configurations.configureEach {
resolutionStrategy {
force "com.theoplayer.theoplayer-sdk-android:integration-ads:${theoplayer_sdk_version}"
force "com.theoplayer.theoplayer-sdk-android:integration-ads-ima:${theoplayer_sdk_version}"
force "com.theoplayer.theoplayer-sdk-android:integration-ads-dai:${theoplayer_sdk_version}"
}
}

3 changes: 3 additions & 0 deletions ios/THEOplayerRCTPlayerAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
var backgroundAudio = BackgroundAudioConfig()
backgroundAudio.enabled = configDict["enabled"] as? Bool ?? false
backgroundAudio.shouldResumeAfterInterruption = configDict["shouldResumeAfterInterruption"] as? Bool ?? false
if let audioSessionModeString = configDict["audioSessionMode"] as? String {
backgroundAudio.audioSessionMode = THEOplayerRCTTypeUtils.audioSessionModeFromString(audioSessionModeString)
}
return backgroundAudio
}

Expand Down
12 changes: 12 additions & 0 deletions ios/THEOplayerRCTTypeUtils.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// THEOplayerRCTTypeUtils.swift

import Foundation
import AVKit
import THEOplayerSDK

let NAN_VALUE: Double = -1.0
Expand Down Expand Up @@ -111,6 +112,17 @@ class THEOplayerRCTTypeUtils {
return AdIntegrationKind.custom
}
}

class func audioSessionModeFromString(_ audioSessionModeString: String) -> AVAudioSession.Mode {
switch audioSessionModeString {
case "moviePlayback":
return .moviePlayback
case "spokenAudio":
return .spokenAudio
default:
return .moviePlayback
}
}

#if os(iOS)
class func cacheStatusToString(_ status: CacheStatus) -> String {
Expand Down
1 change: 1 addition & 0 deletions ios/THEOplayerRCTView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class THEOplayerRCTView: UIView {
var backgroundAudioConfig = BackgroundAudioConfig() {
didSet {
self.updateInterruptionNotifications()
self.updateAVAudioSessionMode()
}
}

Expand Down
13 changes: 13 additions & 0 deletions ios/backgroundAudio/THEOplayerRCTView+BackgroundAudioConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import Foundation
import THEOplayerSDK
import AVFAudio
import AVKit

struct BackgroundAudioConfig {
var enabled: Bool = false
var shouldResumeAfterInterruption: Bool = false
var audioSessionMode: AVAudioSession.Mode = .moviePlayback
}

extension THEOplayerRCTView: BackgroundPlaybackDelegate {
Expand Down Expand Up @@ -46,6 +48,17 @@ extension THEOplayerRCTView: BackgroundPlaybackDelegate {
}
}

func updateAVAudioSessionMode() {
do {
THEOplayer.automaticallyManageAudioSession = (self.backgroundAudioConfig.audioSessionMode == .moviePlayback)
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: self.backgroundAudioConfig.audioSessionMode)
if self.backgroundAudioConfig.audioSessionMode != .moviePlayback {
print("[NATIVE] AVAudioSession mode updated to \(self.backgroundAudioConfig.audioSessionMode.rawValue)")
}
} catch {
print("[NATIVE] Unable to update AVAudioSession mode to \(self.backgroundAudioConfig.audioSessionMode.rawValue): ", error)
}
}

@objc func handleInterruption(notification: Notification) {
guard let userInfo = notification.userInfo,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-theoplayer",
"version": "8.2.2",
"version": "8.3.0",
"description": "A THEOplayer video component for react-native.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
17 changes: 15 additions & 2 deletions src/api/backgroundAudio/BackgroundAudioConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ export interface BackgroundAudioConfiguration {
readonly enabled?: boolean;

/**
* Whether background audio should be resumed after an interruption (e.g. incoming call ended).
* Whether background audio should be resumed after an interruption on iOS (e.g. incoming call).
*
* @defaultValue `false`
* @remark Applies to iOS only, impacting behaviour for handling interruptions while on the lockscreen.
* @remark Applies to iOS only, impacting behaviour for handling interruptions.
*/
readonly shouldResumeAfterInterruption?: boolean;

/**
* Specify the mode for the native iOS AVAudioSession.
*
* @defaultValue `AudioSessionMode.MOVIE_PLAYBACK`
* @remark Applies to iOS only, impacting behaviour for handling interruptions.
*/
readonly audioSessionMode?: AudioSessionMode;
}

export enum AudioSessionMode {
MOVIE_PLAYBACK = 'moviePlayback',
SPOKEN_AUDIO = 'spokenAudio'
}