Skip to content

Commit 5f0ef2c

Browse files
committed
Merge branch 'release/0.2.11'
2 parents 55e468a + da1b66f commit 5f0ef2c

11 files changed

+690
-14
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Conf
384384
| **`position`** | Returns promise that then returns the current position of the player in seconds. | `none` |
385385
| **`toggleSpeed`** | Toggles the player speed one of `0.5`, `1.0`, `1.5`, `2.0`. | `none` |
386386
| **`setSpeed`** | Sets the player speed. | `Double` |
387+
| **`setVolume`** | Sets the player volume. | `Double` |
387388
| **`setPlaylistIndex`** | Sets the current playing item in the loaded playlist. | `Int` |
388389
| **`setControls`** | Sets the display of the control buttons on the player. | `Boolean` |
389390
| **`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` |
@@ -393,6 +394,7 @@ public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Conf
393394
| **`getAudioTracks`** | Returns promise that returns an array of [AudioTracks](#AudioTrack) | `none` |
394395
| **`getCurrentAudioTrack`** | Returns promise that returns the index of the current audio track in array returned by getAudioTracks | `none` |
395396
| **`setCurrentAudioTrack`** | Sets the current audio track to the audio track at the specified index in the array returned by getAudioTracks | `Int` |
397+
| **`setCurrentCaptions`** | Turns off captions when argument is 0. Setting argument to another integer, sets captions to track at playlistItem.tracks[integer - 1] | `Int` |
396398

397399
## Available callbacks
398400

android/src/main/java/com/appgoalz/rnjwplayer/RNJWPlayerModule.java

+18
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,24 @@ public void execute (NativeViewHierarchyManager nvhm) {
361361
}
362362
}
363363

364+
@ReactMethod
365+
public void setCurrentCaptions(final int reactTag, final int index) {
366+
try {
367+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
368+
uiManager.addUIBlock(new UIBlock() {
369+
public void execute (NativeViewHierarchyManager nvhm) {
370+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
371+
372+
if (playerView != null && playerView.mPlayer != null) {
373+
playerView.mPlayer.setCurrentCaptions(index);
374+
}
375+
}
376+
});
377+
} catch (IllegalViewOperationException e) {
378+
throw e;
379+
}
380+
}
381+
364382
private int stateToInt(PlayerState playerState) {
365383
switch (playerState) {
366384
case IDLE:

index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ declare module "react-native-jw-media-player" {
142142
processSpcUrl?: string;
143143
fairplayCertUrl?: string;
144144
contentUUID?: string;
145+
viewOnly: boolean;
145146
}
146147
interface PropsType {
147148
config: Config;
@@ -176,6 +177,7 @@ declare module "react-native-jw-media-player" {
176177
stop(): void;
177178
toggleSpeed(): void;
178179
setSpeed(speed: number): void;
180+
setVolume(volume: number): void;
179181
setPlaylistIndex(index: number): void;
180182
setControls(show: boolean): void;
181183
setLockScreenControls(show: boolean): void;

index.js

+10
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export default class JWPlayer extends Component {
194194
getAudioTracks: PropTypes.func,
195195
getCurrentAudioTrack: PropTypes.func,
196196
setCurrentAudioTrack: PropTypes.func,
197+
setCurrentCaptions: PropTypes.func,
197198
onAudioTracks: PropTypes.func,
198199
};
199200

@@ -400,6 +401,15 @@ export default class JWPlayer extends Component {
400401
}
401402
}
402403

404+
setCurrentCaptions(index) {
405+
if (RNJWPlayerManager) {
406+
RNJWPlayerManager.setCurrentCaptions(
407+
this.getRNJWPlayerBridgeHandle(),
408+
index
409+
);
410+
}
411+
}
412+
403413
getRNJWPlayerBridgeHandle() {
404414
return ReactNative.findNodeHandle(this.refs[RCT_RNJWPLAYER_REF]);
405415
}

ios/RNJWPlayer.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
1212
s.platform = :ios, "10.0"
1313
s.source = { :git => "https://github.com/chaimPaneth/react-native-jw-media-player.git", :tag => "v#{s.version}" }
1414
s.source_files = "RNJWPlayer/*.{h,m}"
15-
s.dependency 'JWPlayerKit', '~> 4.4.0'
15+
s.dependency 'JWPlayerKit', '~> 4.5.0'
1616
s.dependency 'google-cast-sdk', '~> 4.7.0'
1717
s.dependency 'React'
1818
# s.static_framework = true

ios/RNJWPlayer/RNJWPlayerView.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
#import <AVKit/AVKit.h>
99
#import <JWPlayerKit/JWPlayerKit-swift.h>
1010
#import <GoogleCast/GoogleCast.h>
11+
#import "RNJWPlayerViewController.h"
12+
13+
@class RNJWPlayerViewController;
1114

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

14-
@property(nonatomic, strong)JWPlayerViewController* playerViewController;
17+
@property(nonatomic, strong)RNJWPlayerViewController* playerViewController;
1518
@property(nonatomic, strong)JWPlayerView *playerView;
1619

1720
@property(nonatomic)BOOL pipEnabled;

ios/RNJWPlayer/RNJWPlayerView.m

+23-11
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,12 @@ -(JWPlayerItem*)getPlayerItem:item
372372
NSURL *fileUrl = [NSURL URLWithString:file];
373373
NSString *label = [item objectForKey:@"label"];
374374

375-
JWMediaTrack *trackItem = [JWMediaTrack init];
376375
JWCaptionTrackBuilder* trackBuilder = [[JWCaptionTrackBuilder alloc] init];
377376

378377
[trackBuilder file:fileUrl];
379378
[trackBuilder label:label];
380379

381-
trackItem = [trackBuilder buildAndReturnError:&error];
380+
JWMediaTrack *trackItem = [trackBuilder buildAndReturnError:&error];
382381

383382
[tracksArray addObject:trackItem];
384383
}
@@ -597,8 +596,8 @@ -(void)setupPlayerViewController:config :(JWPlayerConfiguration*)playerConfig
597596
{
598597
[self dismissPlayerViewController];
599598

600-
_playerViewController = [JWPlayerViewController new];
601-
_playerViewController.delegate = self;
599+
_playerViewController = [RNJWPlayerViewController new];
600+
_playerViewController.parentView = self;
602601

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

622+
id allowsPictureInPicturePlayback = config[@"allowsPictureInPicturePlayback"];
623+
if ((allowsPictureInPicturePlayback != nil && allowsPictureInPicturePlayback != (id)[NSNull null])) {
624+
_playerViewController.allowsPictureInPicturePlayback = allowsPictureInPicturePlayback;
625+
}
626+
623627
id styling = config[@"styling"];
624628
[self setStyling:styling];
625629

@@ -685,13 +689,14 @@ -(void)presentPlayerViewController:(JWPlayerConfiguration*)configuration
685689
_playerViewController.interfaceBehavior = JWInterfaceBehaviorHidden;
686690
}
687691
}
688-
689-
_playerViewController.playerView.delegate = self;
690-
_playerViewController.player.delegate = self;
691-
_playerViewController.player.playbackStateDelegate = self;
692-
_playerViewController.player.adDelegate = self;
693-
_playerViewController.player.avDelegate = self;
694-
_playerViewController.player.contentKeyDataSource = self;
692+
693+
// _playerViewController.delegate = self;
694+
// _playerViewController.playerView.delegate = self;
695+
// _playerViewController.player.delegate = self;
696+
// _playerViewController.player.playbackStateDelegate = self;
697+
// _playerViewController.player.adDelegate = self;
698+
// _playerViewController.player.avDelegate = self;
699+
// _playerViewController.player.contentKeyDataSource = self;
695700
}
696701

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

1264+
- (void)jwplayer:(id<JWPlayer>)player updatedCues:(NSArray<JWCue *> * _Nonnull)cues
1265+
{
1266+
if (_playerViewController) {
1267+
[_playerViewController jwplayer:player updatedCues:cues];
1268+
}
1269+
}
1270+
12591271
#pragma mark - JWPlayer Ad Delegate
12601272

12611273
- (void)jwplayer:(id _Nonnull)player adEvent:(JWAdEvent * _Nonnull)event {
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// RNJWPlayerViewController.m
3+
// RNJWPlayer
4+
//
5+
// Created by Chaim Paneth on 3/30/22.
6+
//
7+
8+
#if __has_include("React/RCTViewManager.h")
9+
#import "React/RCTViewManager.h"
10+
#else
11+
#import "RCTViewManager.h"
12+
#endif
13+
14+
#import <UIKit/UIKit.h>
15+
#import <AVKit/AVKit.h>
16+
#import <GoogleCast/GoogleCast.h>
17+
#import <JWPlayerKit/JWPlayerKit.h>
18+
#import "JWPlayerKit/JWPlayerObjCViewController.h"
19+
#import "RNJWPlayerView.h"
20+
21+
@class RNJWPlayerView;
22+
23+
@interface RNJWPlayerViewController : JWPlayerObjCViewController <JWPlayerDelegate, JWPlayerStateDelegate, JWAdDelegate, JWCastDelegate, JWAVDelegate, JWPlayerViewDelegate, JWPlayerViewControllerDelegate, AVPictureInPictureControllerDelegate>
24+
25+
@property(nonatomic, strong)RNJWPlayerView *parentView;
26+
27+
@end

0 commit comments

Comments
 (0)