Skip to content

Commit 55e468a

Browse files
committed
Merge branch 'release/0.2.10'
2 parents f0875a6 + 66e3481 commit 55e468a

File tree

5 files changed

+79
-34
lines changed

5 files changed

+79
-34
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,16 @@ public class RNJWPlayerView extends RelativeLayout implements
181181
private MediaServiceController mMediaServiceController;
182182

183183
private void doBindService() {
184-
mMediaServiceController.bindService();
184+
if (mMediaServiceController != null) {
185+
mMediaServiceController.bindService();
186+
}
185187
}
186188

187189
private void doUnbindService() {
188-
mMediaServiceController.unbindService();
190+
if (mMediaServiceController != null) {
191+
mMediaServiceController.unbindService();
192+
mMediaServiceController = null;
193+
}
189194
}
190195

191196
private static boolean contextHasBug(Context context) {

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ public Map getExportedCustomBubblingEventTypeConstants() {
139139
MapBuilder.of(
140140
"phasedRegistrationNames",
141141
MapBuilder.of("bubbled", "onAudioTracks")))
142-
.put("topControlBarVisible",
143-
MapBuilder.of(
144-
"phasedRegistrationNames",
145-
MapBuilder.of("bubbled", "onControlBarVisible")))
146142
.build();
147143
}
148144

@@ -214,9 +210,8 @@ public void toggleSpeed(RNJWPlayerView root) {
214210

215211
@Override
216212
public void onDropViewInstance(@Nonnull RNJWPlayerView view) {
217-
super.onDropViewInstance(view);
218-
219213
view.destroyPlayer();
214+
super.onDropViewInstance(view);
220215
view = null;
221216
}
222217
}

index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export default class JWPlayer extends Component {
158158
onPlaylist: PropTypes.func,
159159
play: PropTypes.func,
160160
pause: PropTypes.func,
161+
setVolume: PropTypes.func,
161162
toggleSpeed: PropTypes.func,
162163
setSpeed: PropTypes.func,
163164
setPlaylistIndex: PropTypes.func,
@@ -189,7 +190,6 @@ export default class JWPlayer extends Component {
189190
onSeeked: PropTypes.func,
190191
onPlaylistItem: PropTypes.func,
191192
onControlBarVisible: PropTypes.func,
192-
onControlBarVisible: PropTypes.func,
193193
onPlaylistComplete: PropTypes.func,
194194
getAudioTracks: PropTypes.func,
195195
getCurrentAudioTrack: PropTypes.func,
@@ -253,6 +253,12 @@ export default class JWPlayer extends Component {
253253
);
254254
}
255255

256+
setVolume(value) {
257+
if (RNJWPlayerManager) {
258+
RNJWPlayerManager.setVolume(this.getRNJWPlayerBridgeHandle(), value);
259+
}
260+
}
261+
256262
async time() {
257263
if (RNJWPlayerManager) {
258264
try {

ios/RNJWPlayer/RNJWPlayerView.m

+63-24
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,16 @@ - (void)contentKeyWithSPCData:(NSData * _Nonnull)spcData completionHandler:(void
921921

922922
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *, id> *)change context:(void *)context
923923
{
924-
if (_playerView != nil && [object isEqual:_playerView.pictureInPictureController] && [keyPath isEqualToString:@"isPictureInPicturePossible"]) {
925-
924+
if (_playerView != nil || _playerViewController != nil) {
925+
if ([keyPath isEqualToString:@"playbackLikelyToKeepUp"]) {
926+
if (_playerView != nil) {
927+
[_playerView.player play];
928+
} else if (_playerViewController != nil) {
929+
[_playerViewController.player play];
930+
}
931+
} else if (_playerView != nil && [object isEqual:_playerView.pictureInPictureController] && [keyPath isEqualToString:@"isPictureInPicturePossible"]) {
932+
933+
}
926934
}
927935
}
928936

@@ -1143,6 +1151,8 @@ - (void)jwplayer:(id<JWPlayer>)player didLoadPlaylistItem:(JWPlayerItem *)item a
11431151

11441152
self.onPlaylistItem(@{@"playlistItem": [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding], @"index": [NSNumber numberWithInteger:index]});
11451153
}
1154+
1155+
[item addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
11461156
}
11471157

11481158
- (void)jwplayer:(id<JWPlayer>)player didLoadPlaylist:(NSArray<JWPlayerItem *> *)playlist
@@ -1468,46 +1478,75 @@ - (void)initializeAudioSession
14681478
{
14691479
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
14701480

1481+
[[NSNotificationCenter defaultCenter] addObserver:self
1482+
selector:@selector(handleMediaServicesReset)
1483+
name:AVAudioSessionMediaServicesWereResetNotification
1484+
object:audioSession];
1485+
14711486
[[NSNotificationCenter defaultCenter] addObserver: self
14721487
selector: @selector(audioSessionInterrupted:)
14731488
name: AVAudioSessionInterruptionNotification
14741489
object: audioSession];
14751490

1476-
NSError *setCategoryError = nil;
1477-
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionAllowBluetooth|AVAudioSessionCategoryOptionDefaultToSpeaker error:&setCategoryError];
1491+
NSError *categoryError = nil;
1492+
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&categoryError];
1493+
1494+
NSError *modeError = nil;
1495+
[audioSession setMode:AVAudioSessionModeDefault error:&modeError];
14781496

14791497
NSError *activationError = nil;
1480-
success = [audioSession setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&activationError];
1498+
success = [audioSession setActive:YES error:&activationError];
14811499

14821500
[[NSNotificationCenter defaultCenter] addObserver:self
14831501
selector:@selector(applicationWillResignActive:)
14841502
name:UIApplicationWillResignActiveNotification object:nil];
1503+
1504+
[[NSNotificationCenter defaultCenter] addObserver:self
1505+
selector:@selector(applicationWillEnterForeground:)
1506+
name:UIApplicationWillEnterForegroundNotification object:nil];
14851507
}
14861508

1509+
// Interupted
1510+
14871511
-(void)audioSessionInterrupted:(NSNotification*)note
14881512
{
1489-
if ([note.name isEqualToString:AVAudioSessionInterruptionNotification]) {
1490-
NSLog(@"Interruption notification");
1491-
1492-
if ([[note.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) {
1493-
[self audioInterruptionsStarted:note];
1494-
} else {
1495-
[self audioInterruptionsEnded:note];
1496-
}
1513+
NSNumber *interruptionType = [[note userInfo] objectForKey:AVAudioSessionInterruptionTypeKey];
1514+
NSNumber *interruptionOption = [[note userInfo] objectForKey:AVAudioSessionInterruptionOptionKey];
1515+
1516+
switch (interruptionType.unsignedIntegerValue) {
1517+
case AVAudioSessionInterruptionTypeBegan: {
1518+
_wasInterrupted = YES;
1519+
1520+
if (_playerView != nil) {
1521+
[_playerView.player pause];
1522+
} else if (_playerViewController != nil) {
1523+
[_playerViewController.player pause];
1524+
}
1525+
} break;
1526+
case AVAudioSessionInterruptionTypeEnded: {
1527+
if (interruptionOption.unsignedIntegerValue == AVAudioSessionInterruptionOptionShouldResume || (!_userPaused && _backgroundAudioEnabled)) {
1528+
if (_playerView != nil) {
1529+
[self->_playerView.player play];
1530+
} else if (_playerViewController != nil) {
1531+
[self->_playerViewController.player play];
1532+
}
1533+
}
1534+
} break;
1535+
default:
1536+
break;
14971537
}
14981538
}
14991539

1500-
-(void)audioInterruptionsStarted:(NSNotification *)note {
1501-
_wasInterrupted = YES;
1502-
1503-
if (_playerView != nil) {
1504-
[_playerView.player pause];
1505-
} else if (_playerViewController != nil) {
1506-
[_playerViewController.player pause];
1507-
}
1540+
// Service reset
1541+
1542+
-(void)handleMediaServicesReset
1543+
{
1544+
// • Handle this notification by fully reconfiguring audio
15081545
}
15091546

1510-
-(void)audioInterruptionsEnded:(NSNotification *)note {
1547+
// Inactive
1548+
// Hack for ios 14 stopping audio when going to background
1549+
-(void)applicationWillResignActive:(NSNotification *)notification {
15111550
if (!_userPaused && _backgroundAudioEnabled) {
15121551
if (_playerView != nil) {
15131552
[_playerView.player play];
@@ -1517,9 +1556,9 @@ -(void)audioInterruptionsEnded:(NSNotification *)note {
15171556
}
15181557
}
15191558

1520-
// Inactive
1559+
// Active
15211560

1522-
-(void)applicationWillResignActive:(NSNotification *)notification {
1561+
-(void)applicationWillEnterForeground:(NSNotification *)notification{
15231562
if (!_userPaused && _backgroundAudioEnabled) {
15241563
if (_playerView != nil) {
15251564
[_playerView.player play];

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-jw-media-player",
3-
"version": "0.2.9",
3+
"version": "0.2.10",
44
"description": "React-native Android/iOS plugin for JWPlayer SDK (https://www.jwplayer.com/)",
55
"main": "index.js",
66
"types": "./index.d.ts",

0 commit comments

Comments
 (0)