Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tvOS picture-in-picture compilation regression. #1518

Merged
merged 2 commits into from
Mar 13, 2019
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
2 changes: 2 additions & 0 deletions ios/Video/RCTVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@class RCTEventDispatcher;
#if __has_include(<react-native-video/RCTVideoCache.h>)
@interface RCTVideo : UIView <RCTVideoPlayerViewControllerDelegate, DVAssetLoaderDelegatesDelegate>
#elif TARGET_OS_TV
@interface RCTVideo : UIView <RCTVideoPlayerViewControllerDelegate>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the DVAssetLoaderDelegatesDelegate also incompatible with tvOS?

Copy link
Contributor Author

@FullstackJack FullstackJack Mar 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it appears so since it compiles. Also made me realize I shouldn't have copied in AVAssetResourceLoaderDelegate when I started working so I removed it. That delegate does not exist in master.

#else
@interface RCTVideo : UIView <RCTVideoPlayerViewControllerDelegate, AVPictureInPictureControllerDelegate>
#endif
Expand Down
29 changes: 20 additions & 9 deletions ios/Video/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ @implementation RCTVideo
AVPlayer *_player;
AVPlayerItem *_playerItem;
NSDictionary *_source;
AVPictureInPictureController *_pipController;
void (^__strong _Nonnull _restoreUserInterfaceForPIPStopCompletionHandler)(BOOL);
BOOL _playerItemObserversSet;
BOOL _playerBufferEmpty;
AVPlayerLayer *_playerLayer;
Expand Down Expand Up @@ -79,6 +77,10 @@ @implementation RCTVideo
#if __has_include(<react-native-video/RCTVideoCache.h>)
RCTVideoCache * _videoCache;
#endif
#if TARGET_OS_IOS
void (^__strong _Nonnull _restoreUserInterfaceForPIPStopCompletionHandler)(BOOL);
AVPictureInPictureController *_pipController;
#endif
}

- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
Expand All @@ -103,9 +105,11 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
_playInBackground = false;
_allowsExternalPlayback = YES;
_playWhenInactive = false;
_pictureInPicture = false;
_pictureInPicture = false;
_ignoreSilentSwitch = @"inherit"; // inherit, ignore, obey
_restoreUserInterfaceForPIPStopCompletionHandler = NULL;
#if TARGET_OS_IOS
_restoreUserInterfaceForPIPStopCompletionHandler = NULL;
#endif
#if __has_include(<react-native-video/RCTVideoCache.h>)
_videoCache = [RCTVideoCache sharedInstance];
#endif
Expand Down Expand Up @@ -793,6 +797,7 @@ - (void)setPlayWhenInactive:(BOOL)playWhenInactive

- (void)setPictureInPicture:(BOOL)pictureInPicture
{
#if TARGET_OS_IOS
if (_pictureInPicture == pictureInPicture) {
return;
}
Expand All @@ -807,8 +812,10 @@ - (void)setPictureInPicture:(BOOL)pictureInPicture
[_pipController stopPictureInPicture];
});
}
#endif
}

#if TARGET_OS_IOS
- (void)setRestoreUserInterfaceForPIPStopCompletionHandler:(BOOL)restore
{
if (_restoreUserInterfaceForPIPStopCompletionHandler != NULL) {
Expand All @@ -824,6 +831,7 @@ - (void)setupPipController {
_pipController.delegate = self;
}
}
#endif

- (void)setIgnoreSilentSwitch:(NSString *)ignoreSilentSwitch
{
Expand Down Expand Up @@ -1279,8 +1287,9 @@ - (void)usePlayerLayer

[self.layer addSublayer:_playerLayer];
self.layer.needsDisplayOnBoundsChange = YES;

#if TARGET_OS_IOS
[self setupPipController];
#endif
}
}

Expand Down Expand Up @@ -1539,19 +1548,20 @@ - (NSString *)cacheDirectoryPath {

#pragma mark - Picture in Picture

#if TARGET_OS_IOS
- (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
if (self.onPictureInPictureStatusChanged) {
self.onPictureInPictureStatusChanged(@{
@"isActive": [NSNumber numberWithBool:false]
});
@"isActive": [NSNumber numberWithBool:false]
});
}
}

- (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
if (self.onPictureInPictureStatusChanged) {
self.onPictureInPictureStatusChanged(@{
@"isActive": [NSNumber numberWithBool:true]
});
@"isActive": [NSNumber numberWithBool:true]
});
}
}

Expand All @@ -1574,5 +1584,6 @@ - (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPict
}
_restoreUserInterfaceForPIPStopCompletionHandler = completionHandler;
}
#endif

@end