Skip to content
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
50 changes: 26 additions & 24 deletions ios/RNJWPlayer/RNJWPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ class RNJWPlayerView : UIView, JWPlayerDelegate, JWPlayerStateDelegate, JWAdDele
}
}

func setCategory(categoryName:String!, categoryOptions:[String]!) {
func setCategory(categoryName:String!, categoryOptions:[String]?) {
if (audioSession == nil) {
audioSession = AVAudioSession.sharedInstance()
}
Expand All @@ -1491,29 +1491,31 @@ 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(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
19 changes: 1 addition & 18 deletions ios/RNJWPlayer/RNJWPlayerViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,6 @@ @interface RCT_EXTERN_MODULE(RNJWPlayerViewManager, RCTViewManager)

RCT_EXTERN_METHOD(setFullscreen: (nonnull NSNumber *)reactTag: (BOOL)fullscreen)

RCT_EXPORT_METHOD(setMute: (nonnull NSNumber *)reactTag :(BOOL)isMuted) {
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNJWPlayerView *> *viewRegistry) {
RNJWPlayerView *view = viewRegistry[reactTag];
if (![view isKindOfClass:[RNJWPlayerView class]]) {
RCTLogError(@"Invalid view returned from registry, expecting RNJWPlayerView, got: %@", view);
return;
}

/// From JWPlayer - The volume relative to the volume of the device. All values are clamped from 0.0 (mute) to 1.0 (current volume of the device).
CGFloat volume = isMuted ? 0.0 : 1.0;

if (view.playerView) {
[view.playerView.player setVolume:volume];
} else if (view.playerViewController) {
[view.playerViewController.player setVolume:volume];
}
}];
}
RCT_EXTERN_METHOD(setMute: (nonnull NSNumber *)reactTag :(BOOL)isMuted)

@end
18 changes: 18 additions & 0 deletions ios/RNJWPlayer/RNJWPlayerViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@ class RNJWPlayerViewManager: RCTViewManager {
}
}

@objc func setMute(_ reactTag: NSNumber, _ isMuted: Bool) {
self.bridge.uiManager.addUIBlock { uiManager, viewRegistry in
guard let view = viewRegistry?[reactTag] as? RNJWPlayerView else {
print("Invalid view returned from registry, expecting RNJWPlayerView, got: \(String(describing: viewRegistry?[reactTag]))")
return
}

/// From JWPlayer - The volume relative to the volume of the device. All values are clamped from 0.0 (mute) to 1.0 (current volume of the device).
let volume: CGFloat = isMuted ? 0.0 : 1.0

if let playerView = view.playerView {
playerView.player.volume = volume
} else if let playerViewController = view.playerViewController {
playerViewController.player.volume = volume
}
}
}


@objc func togglePIP(_ reactTag: NSNumber) {
self.bridge.uiManager.addUIBlock { uiManager, viewRegistry in
Expand Down