diff --git a/ios/RNJWPlayer/RNJWPlayerView.swift b/ios/RNJWPlayer/RNJWPlayerView.swift index 32d85a5..6c9a68d 100644 --- a/ios/RNJWPlayer/RNJWPlayerView.swift +++ b/ios/RNJWPlayer/RNJWPlayerView.swift @@ -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() } @@ -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 + } } } diff --git a/ios/RNJWPlayer/RNJWPlayerViewManager.m b/ios/RNJWPlayer/RNJWPlayerViewManager.m index 85a1958..24ceafb 100644 --- a/ios/RNJWPlayer/RNJWPlayerViewManager.m +++ b/ios/RNJWPlayer/RNJWPlayerViewManager.m @@ -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 *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 diff --git a/ios/RNJWPlayer/RNJWPlayerViewManager.swift b/ios/RNJWPlayer/RNJWPlayerViewManager.swift index 68e4812..d8a143a 100644 --- a/ios/RNJWPlayer/RNJWPlayerViewManager.swift +++ b/ios/RNJWPlayer/RNJWPlayerViewManager.swift @@ -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