Skip to content

Commit

Permalink
Merge branch 'release/0.2.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
chaimPaneth committed Apr 4, 2022
2 parents 55e468a + da1b66f commit 5f0ef2c
Show file tree
Hide file tree
Showing 11 changed files with 690 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Conf
| **`position`** | Returns promise that then returns the current position of the player in seconds. | `none` |
| **`toggleSpeed`** | Toggles the player speed one of `0.5`, `1.0`, `1.5`, `2.0`. | `none` |
| **`setSpeed`** | Sets the player speed. | `Double` |
| **`setVolume`** | Sets the player volume. | `Double` |
| **`setPlaylistIndex`** | Sets the current playing item in the loaded playlist. | `Int` |
| **`setControls`** | Sets the display of the control buttons on the player. | `Boolean` |
| **`setLockScreenControls`** | *(iOS only)* Sets the locks screen controls for the currently playing media, can be used to control what player to show the controls for. | `Boolean` |
Expand All @@ -393,6 +394,7 @@ public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Conf
| **`getAudioTracks`** | Returns promise that returns an array of [AudioTracks](#AudioTrack) | `none` |
| **`getCurrentAudioTrack`** | Returns promise that returns the index of the current audio track in array returned by getAudioTracks | `none` |
| **`setCurrentAudioTrack`** | Sets the current audio track to the audio track at the specified index in the array returned by getAudioTracks | `Int` |
| **`setCurrentCaptions`** | Turns off captions when argument is 0. Setting argument to another integer, sets captions to track at playlistItem.tracks[integer - 1] | `Int` |

## Available callbacks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,24 @@ public void execute (NativeViewHierarchyManager nvhm) {
}
}

@ReactMethod
public void setCurrentCaptions(final int reactTag, final int index) {
try {
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
uiManager.addUIBlock(new UIBlock() {
public void execute (NativeViewHierarchyManager nvhm) {
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

if (playerView != null && playerView.mPlayer != null) {
playerView.mPlayer.setCurrentCaptions(index);
}
}
});
} catch (IllegalViewOperationException e) {
throw e;
}
}

private int stateToInt(PlayerState playerState) {
switch (playerState) {
case IDLE:
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ declare module "react-native-jw-media-player" {
processSpcUrl?: string;
fairplayCertUrl?: string;
contentUUID?: string;
viewOnly: boolean;
}
interface PropsType {
config: Config;
Expand Down Expand Up @@ -176,6 +177,7 @@ declare module "react-native-jw-media-player" {
stop(): void;
toggleSpeed(): void;
setSpeed(speed: number): void;
setVolume(volume: number): void;
setPlaylistIndex(index: number): void;
setControls(show: boolean): void;
setLockScreenControls(show: boolean): void;
Expand Down
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export default class JWPlayer extends Component {
getAudioTracks: PropTypes.func,
getCurrentAudioTrack: PropTypes.func,
setCurrentAudioTrack: PropTypes.func,
setCurrentCaptions: PropTypes.func,
onAudioTracks: PropTypes.func,
};

Expand Down Expand Up @@ -400,6 +401,15 @@ export default class JWPlayer extends Component {
}
}

setCurrentCaptions(index) {
if (RNJWPlayerManager) {
RNJWPlayerManager.setCurrentCaptions(
this.getRNJWPlayerBridgeHandle(),
index
);
}
}

getRNJWPlayerBridgeHandle() {
return ReactNative.findNodeHandle(this.refs[RCT_RNJWPLAYER_REF]);
}
Expand Down
2 changes: 1 addition & 1 deletion ios/RNJWPlayer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.platform = :ios, "10.0"
s.source = { :git => "https://github.com/chaimPaneth/react-native-jw-media-player.git", :tag => "v#{s.version}" }
s.source_files = "RNJWPlayer/*.{h,m}"
s.dependency 'JWPlayerKit', '~> 4.4.0'
s.dependency 'JWPlayerKit', '~> 4.5.0'
s.dependency 'google-cast-sdk', '~> 4.7.0'
s.dependency 'React'
# s.static_framework = true
Expand Down
5 changes: 4 additions & 1 deletion ios/RNJWPlayer/RNJWPlayerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
#import <AVKit/AVKit.h>
#import <JWPlayerKit/JWPlayerKit-swift.h>
#import <GoogleCast/GoogleCast.h>
#import "RNJWPlayerViewController.h"

@class RNJWPlayerViewController;

@interface RNJWPlayerView : UIView <JWPlayerDelegate, JWPlayerStateDelegate, JWAdDelegate, JWCastDelegate, JWAVDelegate, JWPlayerViewDelegate, JWPlayerViewControllerDelegate, JWDRMContentKeyDataSource, AVPictureInPictureControllerDelegate>

@property(nonatomic, strong)JWPlayerViewController* playerViewController;
@property(nonatomic, strong)RNJWPlayerViewController* playerViewController;
@property(nonatomic, strong)JWPlayerView *playerView;

@property(nonatomic)BOOL pipEnabled;
Expand Down
34 changes: 23 additions & 11 deletions ios/RNJWPlayer/RNJWPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,12 @@ -(JWPlayerItem*)getPlayerItem:item
NSURL *fileUrl = [NSURL URLWithString:file];
NSString *label = [item objectForKey:@"label"];

JWMediaTrack *trackItem = [JWMediaTrack init];
JWCaptionTrackBuilder* trackBuilder = [[JWCaptionTrackBuilder alloc] init];

[trackBuilder file:fileUrl];
[trackBuilder label:label];

trackItem = [trackBuilder buildAndReturnError:&error];
JWMediaTrack *trackItem = [trackBuilder buildAndReturnError:&error];

[tracksArray addObject:trackItem];
}
Expand Down Expand Up @@ -597,8 +596,8 @@ -(void)setupPlayerViewController:config :(JWPlayerConfiguration*)playerConfig
{
[self dismissPlayerViewController];

_playerViewController = [JWPlayerViewController new];
_playerViewController.delegate = self;
_playerViewController = [RNJWPlayerViewController new];
_playerViewController.parentView = self;

id interfaceBehavior = config[@"interfaceBehavior"];
if ((interfaceBehavior != nil) && (interfaceBehavior != (id)[NSNull null])) {
Expand All @@ -620,6 +619,11 @@ -(void)setupPlayerViewController:config :(JWPlayerConfiguration*)playerConfig
_playerViewController.enableLockScreenControls = YES;
}

id allowsPictureInPicturePlayback = config[@"allowsPictureInPicturePlayback"];
if ((allowsPictureInPicturePlayback != nil && allowsPictureInPicturePlayback != (id)[NSNull null])) {
_playerViewController.allowsPictureInPicturePlayback = allowsPictureInPicturePlayback;
}

id styling = config[@"styling"];
[self setStyling:styling];

Expand Down Expand Up @@ -685,13 +689,14 @@ -(void)presentPlayerViewController:(JWPlayerConfiguration*)configuration
_playerViewController.interfaceBehavior = JWInterfaceBehaviorHidden;
}
}

_playerViewController.playerView.delegate = self;
_playerViewController.player.delegate = self;
_playerViewController.player.playbackStateDelegate = self;
_playerViewController.player.adDelegate = self;
_playerViewController.player.avDelegate = self;
_playerViewController.player.contentKeyDataSource = self;

// _playerViewController.delegate = self;
// _playerViewController.playerView.delegate = self;
// _playerViewController.player.delegate = self;
// _playerViewController.player.playbackStateDelegate = self;
// _playerViewController.player.adDelegate = self;
// _playerViewController.player.avDelegate = self;
// _playerViewController.player.contentKeyDataSource = self;
}

#pragma mark - JWPlayer View helpers
Expand Down Expand Up @@ -1256,6 +1261,13 @@ - (void)jwplayer:(id<JWPlayer>)player playbackRateChangedTo:(double)rate at:(NST
}
}

- (void)jwplayer:(id<JWPlayer>)player updatedCues:(NSArray<JWCue *> * _Nonnull)cues
{
if (_playerViewController) {
[_playerViewController jwplayer:player updatedCues:cues];
}
}

#pragma mark - JWPlayer Ad Delegate

- (void)jwplayer:(id _Nonnull)player adEvent:(JWAdEvent * _Nonnull)event {
Expand Down
27 changes: 27 additions & 0 deletions ios/RNJWPlayer/RNJWPlayerViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// RNJWPlayerViewController.m
// RNJWPlayer
//
// Created by Chaim Paneth on 3/30/22.
//

#if __has_include("React/RCTViewManager.h")
#import "React/RCTViewManager.h"
#else
#import "RCTViewManager.h"
#endif

#import <UIKit/UIKit.h>
#import <AVKit/AVKit.h>
#import <GoogleCast/GoogleCast.h>
#import <JWPlayerKit/JWPlayerKit.h>
#import "JWPlayerKit/JWPlayerObjCViewController.h"
#import "RNJWPlayerView.h"

@class RNJWPlayerView;

@interface RNJWPlayerViewController : JWPlayerObjCViewController <JWPlayerDelegate, JWPlayerStateDelegate, JWAdDelegate, JWCastDelegate, JWAVDelegate, JWPlayerViewDelegate, JWPlayerViewControllerDelegate, AVPictureInPictureControllerDelegate>

@property(nonatomic, strong)RNJWPlayerView *parentView;

@end
Loading

0 comments on commit 5f0ef2c

Please sign in to comment.