Skip to content

[BUG] PiP not working on iOS #85

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

Merged
merged 2 commits into from
Sep 25, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ If you use a different provider for DRM or this does not work for your use case,
1. Read and understand the requirements for PiP in the [iOS SDK](https://docs.jwplayer.com/players/docs/ios-invoke-picture-in-picture-playback). PiP mode is enabled by JWP for the `PlayerViewController`.
2. (viewOnly:true only) Set the `pipEnabled` prop to `true`.
3. (viewOnly:true only) Call `togglePIP()` to enable or disable PiP.
4. Ensure [category](/docs//legacy_readme.md#audiosessioncategory) and/or [categoryOptions](/docs//legacy_readme.md#audiosessioncategoryoptions) prop(s) are set to define and configure your media. This is required to setup the audio session. If `category` is not defined but `pipEnabled` is set true, we default to the standard `playback` category to avoid crashing.

<br /><br />

Expand Down
51 changes: 27 additions & 24 deletions ios/RNJWPlayer/RNJWPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class RNJWPlayerView : UIView, JWPlayerDelegate, JWPlayerStateDelegate, JWAdDele
}

if backgroundAudioEnabled || pipEnabled {
let category = config["category"] as? String
let category = config["category"] != nil ? config["category"] as? String : "playback" // default category for playback
let categoryOptions = config["categoryOptions"] as? [String]
let mode = config["mode"] as? String

Expand Down Expand Up @@ -1518,29 +1518,32 @@ class RNJWPlayerView : UIView, JWPlayerDelegate, JWPlayerStateDelegate, JWAdDele
}

var options: AVAudioSession.CategoryOptions = []
if categoryOptions.contains("MixWithOthers") {
options.insert(.mixWithOthers)
}
if categoryOptions.contains("DuckOthers") {
options.insert(.duckOthers)
}
if categoryOptions.contains("AllowBluetooth") {
options.insert(.allowBluetooth)
}
if categoryOptions.contains("InterruptSpokenAudioAndMix") {
options.insert(.interruptSpokenAudioAndMixWithOthers)
}
if categoryOptions.contains("AllowBluetoothA2DP") {
options.insert(.allowBluetoothA2DP)
}
if categoryOptions.contains("AllowAirPlay") {
options.insert(.allowAirPlay)
}
if categoryOptions.contains("OverrideMutedMicrophone") {
if #available(iOS 14.5, *) {
options.insert(.overrideMutedMicrophoneInterruption)
} else {
// Handle the case for earlier versions if needed
// If the user doesn't specify any options
if categoryOptions != nil {
if categoryOptions.contains("MixWithOthers") {
options.insert(.mixWithOthers)
}
if categoryOptions.contains("DuckOthers") {
options.insert(.duckOthers)
}
if categoryOptions.contains("AllowBluetooth") {
options.insert(.allowBluetooth)
}
if categoryOptions.contains("InterruptSpokenAudioAndMix") {
options.insert(.interruptSpokenAudioAndMixWithOthers)
}
if categoryOptions.contains("AllowBluetoothA2DP") {
options.insert(.allowBluetoothA2DP)
}
if categoryOptions.contains("AllowAirPlay") {
options.insert(.allowAirPlay)
}
if categoryOptions.contains("OverrideMutedMicrophone") {
if #available(iOS 14.5, *) {
options.insert(.overrideMutedMicrophoneInterruption)
} else {
// Handle the case for earlier versions if needed
}
}
}

Expand Down