Clean project structure (#320)
This commit is contained in:
committed by
Matt Apperson
parent
8c9168b582
commit
0c746e8fe8
16
ios/RCTVideo.h
Normal file
16
ios/RCTVideo.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#import "RCTView.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import "AVKit/AVKit.h"
|
||||
#import "UIView+FindUIViewController.h"
|
||||
#import "RCTVideoPlayerViewController.h"
|
||||
#import "RCTVideoPlayerViewControllerDelegate.h"
|
||||
|
||||
@class RCTEventDispatcher;
|
||||
|
||||
@interface RCTVideo : UIView <RCTVideoPlayerViewControllerDelegate>
|
||||
|
||||
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem;
|
||||
|
||||
@end
|
749
ios/RCTVideo.m
Normal file
749
ios/RCTVideo.m
Normal file
@@ -0,0 +1,749 @@
|
||||
#import "RCTConvert.h"
|
||||
#import "RCTVideo.h"
|
||||
#import "RCTBridgeModule.h"
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "UIView+React.h"
|
||||
|
||||
static NSString *const statusKeyPath = @"status";
|
||||
static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp";
|
||||
static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
|
||||
static NSString *const readyForDisplayKeyPath = @"readyForDisplay";
|
||||
static NSString *const playbackRate = @"rate";
|
||||
|
||||
@implementation RCTVideo
|
||||
{
|
||||
AVPlayer *_player;
|
||||
AVPlayerItem *_playerItem;
|
||||
BOOL _playerItemObserversSet;
|
||||
BOOL _playerBufferEmpty;
|
||||
AVPlayerLayer *_playerLayer;
|
||||
AVPlayerViewController *_playerViewController;
|
||||
NSURL *_videoURL;
|
||||
|
||||
/* Required to publish events */
|
||||
RCTEventDispatcher *_eventDispatcher;
|
||||
BOOL _playbackRateObserverRegistered;
|
||||
|
||||
bool _pendingSeek;
|
||||
float _pendingSeekTime;
|
||||
float _lastSeekTime;
|
||||
|
||||
/* For sending videoProgress events */
|
||||
Float64 _progressUpdateInterval;
|
||||
BOOL _controls;
|
||||
id _timeObserver;
|
||||
|
||||
/* Keep track of any modifiers, need to be applied after each play */
|
||||
float _volume;
|
||||
float _rate;
|
||||
BOOL _muted;
|
||||
BOOL _paused;
|
||||
BOOL _repeat;
|
||||
BOOL _playbackStalled;
|
||||
BOOL _playInBackground;
|
||||
BOOL _playWhenInactive;
|
||||
NSString * _resizeMode;
|
||||
BOOL _fullscreenPlayerPresented;
|
||||
UIViewController * _presentingViewController;
|
||||
}
|
||||
|
||||
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
_eventDispatcher = eventDispatcher;
|
||||
|
||||
_playbackRateObserverRegistered = NO;
|
||||
_playbackStalled = NO;
|
||||
_rate = 1.0;
|
||||
_volume = 1.0;
|
||||
_resizeMode = @"AVLayerVideoGravityResizeAspectFill";
|
||||
_pendingSeek = false;
|
||||
_pendingSeekTime = 0.0f;
|
||||
_lastSeekTime = 0.0f;
|
||||
_progressUpdateInterval = 250;
|
||||
_controls = NO;
|
||||
_playerBufferEmpty = YES;
|
||||
_playInBackground = false;
|
||||
_playWhenInactive = false;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationWillResignActive:)
|
||||
name:UIApplicationWillResignActiveNotification
|
||||
object:nil];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationDidEnterBackground:)
|
||||
name:UIApplicationDidEnterBackgroundNotification
|
||||
object:nil];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationWillEnterForeground:)
|
||||
name:UIApplicationWillEnterForegroundNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem {
|
||||
RCTVideoPlayerViewController* playerLayer= [[RCTVideoPlayerViewController alloc] init];
|
||||
playerLayer.showsPlaybackControls = NO;
|
||||
playerLayer.rctDelegate = self;
|
||||
playerLayer.view.frame = self.bounds;
|
||||
playerLayer.player = _player;
|
||||
playerLayer.view.frame = self.bounds;
|
||||
return playerLayer;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------
|
||||
** Get the duration for a AVPlayerItem.
|
||||
** ------------------------------------------------------- */
|
||||
|
||||
- (CMTime)playerItemDuration
|
||||
{
|
||||
AVPlayerItem *playerItem = [_player currentItem];
|
||||
if (playerItem.status == AVPlayerItemStatusReadyToPlay)
|
||||
{
|
||||
return([playerItem duration]);
|
||||
}
|
||||
|
||||
return(kCMTimeInvalid);
|
||||
}
|
||||
|
||||
- (CMTimeRange)playerItemSeekableTimeRange
|
||||
{
|
||||
AVPlayerItem *playerItem = [_player currentItem];
|
||||
if (playerItem.status == AVPlayerItemStatusReadyToPlay)
|
||||
{
|
||||
return [playerItem seekableTimeRanges].firstObject.CMTimeRangeValue;
|
||||
}
|
||||
|
||||
return (kCMTimeRangeZero);
|
||||
}
|
||||
|
||||
|
||||
/* Cancels the previously registered time observer. */
|
||||
-(void)removePlayerTimeObserver
|
||||
{
|
||||
if (_timeObserver)
|
||||
{
|
||||
[_player removeTimeObserver:_timeObserver];
|
||||
_timeObserver = nil;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Progress
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[self removePlayerItemObservers];
|
||||
[_player removeObserver:self forKeyPath:playbackRate context:nil];
|
||||
}
|
||||
|
||||
#pragma mark - App lifecycle handlers
|
||||
|
||||
- (void)applicationWillResignActive:(NSNotification *)notification
|
||||
{
|
||||
if (_playInBackground || _playWhenInactive || _paused) return;
|
||||
|
||||
[_player pause];
|
||||
[_player setRate:0.0];
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(NSNotification *)notification
|
||||
{
|
||||
if (_playInBackground) {
|
||||
// Needed to play sound in background. See https://developer.apple.com/library/ios/qa/qa1668/_index.html
|
||||
[_playerLayer setPlayer:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
||||
{
|
||||
[self applyModifiers];
|
||||
if (_playInBackground) {
|
||||
[_playerLayer setPlayer:_player];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Progress
|
||||
|
||||
- (void)sendProgressUpdate
|
||||
{
|
||||
AVPlayerItem *video = [_player currentItem];
|
||||
if (video == nil || video.status != AVPlayerItemStatusReadyToPlay) {
|
||||
return;
|
||||
}
|
||||
|
||||
CMTime playerDuration = [self playerItemDuration];
|
||||
if (CMTIME_IS_INVALID(playerDuration)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CMTime currentTime = _player.currentTime;
|
||||
const Float64 duration = CMTimeGetSeconds(playerDuration);
|
||||
const Float64 currentTimeSecs = CMTimeGetSeconds(currentTime);
|
||||
if( currentTimeSecs >= 0) {
|
||||
[_eventDispatcher sendInputEventWithName:@"onVideoProgress"
|
||||
body:@{
|
||||
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(currentTime)],
|
||||
@"playableDuration": [self calculatePlayableDuration],
|
||||
@"atValue": [NSNumber numberWithLongLong:currentTime.value],
|
||||
@"atTimescale": [NSNumber numberWithInt:currentTime.timescale],
|
||||
@"target": self.reactTag,
|
||||
@"seekableDuration": [NSNumber numberWithFloat:CMTimeGetSeconds([self playerItemSeekableTimeRange].duration)],
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* Calculates and returns the playable duration of the current player item using its loaded time ranges.
|
||||
*
|
||||
* \returns The playable duration of the current player item in seconds.
|
||||
*/
|
||||
- (NSNumber *)calculatePlayableDuration
|
||||
{
|
||||
AVPlayerItem *video = _player.currentItem;
|
||||
if (video.status == AVPlayerItemStatusReadyToPlay) {
|
||||
__block CMTimeRange effectiveTimeRange;
|
||||
[video.loadedTimeRanges enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
CMTimeRange timeRange = [obj CMTimeRangeValue];
|
||||
if (CMTimeRangeContainsTime(timeRange, video.currentTime)) {
|
||||
effectiveTimeRange = timeRange;
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
Float64 playableDuration = CMTimeGetSeconds(CMTimeRangeGetEnd(effectiveTimeRange));
|
||||
if (playableDuration > 0) {
|
||||
return [NSNumber numberWithFloat:playableDuration];
|
||||
}
|
||||
}
|
||||
return [NSNumber numberWithInteger:0];
|
||||
}
|
||||
|
||||
- (void)addPlayerItemObservers
|
||||
{
|
||||
[_playerItem addObserver:self forKeyPath:statusKeyPath options:0 context:nil];
|
||||
[_playerItem addObserver:self forKeyPath:playbackBufferEmptyKeyPath options:0 context:nil];
|
||||
[_playerItem addObserver:self forKeyPath:playbackLikelyToKeepUpKeyPath options:0 context:nil];
|
||||
_playerItemObserversSet = YES;
|
||||
}
|
||||
|
||||
/* Fixes https://github.com/brentvatne/react-native-video/issues/43
|
||||
* Crashes caused when trying to remove the observer when there is no
|
||||
* observer set */
|
||||
- (void)removePlayerItemObservers
|
||||
{
|
||||
if (_playerItemObserversSet) {
|
||||
[_playerItem removeObserver:self forKeyPath:statusKeyPath];
|
||||
[_playerItem removeObserver:self forKeyPath:playbackBufferEmptyKeyPath];
|
||||
[_playerItem removeObserver:self forKeyPath:playbackLikelyToKeepUpKeyPath];
|
||||
_playerItemObserversSet = NO;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Player and source
|
||||
|
||||
- (void)setSrc:(NSDictionary *)source
|
||||
{
|
||||
[self removePlayerTimeObserver];
|
||||
[self removePlayerItemObservers];
|
||||
_playerItem = [self playerItemForSource:source];
|
||||
[self addPlayerItemObservers];
|
||||
|
||||
[_player pause];
|
||||
[self removePlayerLayer];
|
||||
[_playerViewController.view removeFromSuperview];
|
||||
_playerViewController = nil;
|
||||
|
||||
if (_playbackRateObserverRegistered) {
|
||||
[_player removeObserver:self forKeyPath:playbackRate context:nil];
|
||||
_playbackRateObserverRegistered = NO;
|
||||
}
|
||||
|
||||
_player = [AVPlayer playerWithPlayerItem:_playerItem];
|
||||
_player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
|
||||
|
||||
[_player addObserver:self forKeyPath:playbackRate options:0 context:nil];
|
||||
_playbackRateObserverRegistered = YES;
|
||||
|
||||
const Float64 progressUpdateIntervalMS = _progressUpdateInterval / 1000;
|
||||
// @see endScrubbing in AVPlayerDemoPlaybackViewController.m of https://developer.apple.com/library/ios/samplecode/AVPlayerDemo/Introduction/Intro.html
|
||||
__weak RCTVideo *weakSelf = self;
|
||||
_timeObserver = [_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(progressUpdateIntervalMS, NSEC_PER_SEC)
|
||||
queue:NULL
|
||||
usingBlock:^(CMTime time) { [weakSelf sendProgressUpdate]; }
|
||||
];
|
||||
[_eventDispatcher sendInputEventWithName:@"onVideoLoadStart"
|
||||
body:@{@"src": @{
|
||||
@"uri": [source objectForKey:@"uri"],
|
||||
@"type": [source objectForKey:@"type"],
|
||||
@"isNetwork":[NSNumber numberWithBool:(bool)[source objectForKey:@"isNetwork"]]},
|
||||
@"target": self.reactTag}];
|
||||
}
|
||||
|
||||
- (AVPlayerItem*)playerItemForSource:(NSDictionary *)source
|
||||
{
|
||||
bool isNetwork = [RCTConvert BOOL:[source objectForKey:@"isNetwork"]];
|
||||
bool isAsset = [RCTConvert BOOL:[source objectForKey:@"isAsset"]];
|
||||
NSString *uri = [source objectForKey:@"uri"];
|
||||
NSString *type = [source objectForKey:@"type"];
|
||||
|
||||
NSURL *url = (isNetwork || isAsset) ?
|
||||
[NSURL URLWithString:uri] :
|
||||
[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]];
|
||||
|
||||
if (isAsset) {
|
||||
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
|
||||
return [AVPlayerItem playerItemWithAsset:asset];
|
||||
}
|
||||
|
||||
return [AVPlayerItem playerItemWithURL:url];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||
{
|
||||
if (object == _playerItem) {
|
||||
|
||||
if ([keyPath isEqualToString:statusKeyPath]) {
|
||||
// Handle player item status change.
|
||||
if (_playerItem.status == AVPlayerItemStatusReadyToPlay) {
|
||||
float duration = CMTimeGetSeconds(_playerItem.asset.duration);
|
||||
|
||||
if (isnan(duration)) {
|
||||
duration = 0.0;
|
||||
}
|
||||
|
||||
NSObject *width = @"undefined";
|
||||
NSObject *height = @"undefined";
|
||||
NSString *orientation = @"undefined";
|
||||
|
||||
if ([_playerItem.asset tracksWithMediaType:AVMediaTypeVideo].count > 0) {
|
||||
AVAssetTrack *videoTrack = [[_playerItem.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
|
||||
width = [NSNumber numberWithFloat:videoTrack.naturalSize.width];
|
||||
height = [NSNumber numberWithFloat:videoTrack.naturalSize.height];
|
||||
CGAffineTransform preferredTransform = [videoTrack preferredTransform];
|
||||
|
||||
if ((videoTrack.naturalSize.width == preferredTransform.tx
|
||||
&& videoTrack.naturalSize.height == preferredTransform.ty)
|
||||
|| (preferredTransform.tx == 0 && preferredTransform.ty == 0))
|
||||
{
|
||||
orientation = @"landscape";
|
||||
} else
|
||||
orientation = @"portrait";
|
||||
}
|
||||
|
||||
[_eventDispatcher sendInputEventWithName:@"onVideoLoad"
|
||||
body:@{@"duration": [NSNumber numberWithFloat:duration],
|
||||
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.currentTime)],
|
||||
@"canPlayReverse": [NSNumber numberWithBool:_playerItem.canPlayReverse],
|
||||
@"canPlayFastForward": [NSNumber numberWithBool:_playerItem.canPlayFastForward],
|
||||
@"canPlaySlowForward": [NSNumber numberWithBool:_playerItem.canPlaySlowForward],
|
||||
@"canPlaySlowReverse": [NSNumber numberWithBool:_playerItem.canPlaySlowReverse],
|
||||
@"canStepBackward": [NSNumber numberWithBool:_playerItem.canStepBackward],
|
||||
@"canStepForward": [NSNumber numberWithBool:_playerItem.canStepForward],
|
||||
@"naturalSize": @{
|
||||
@"width": width,
|
||||
@"height": height,
|
||||
@"orientation": orientation
|
||||
},
|
||||
@"target": self.reactTag}];
|
||||
|
||||
[self attachListeners];
|
||||
[self applyModifiers];
|
||||
} else if(_playerItem.status == AVPlayerItemStatusFailed) {
|
||||
[_eventDispatcher sendInputEventWithName:@"onVideoError"
|
||||
body:@{@"error": @{
|
||||
@"code": [NSNumber numberWithInteger: _playerItem.error.code],
|
||||
@"domain": _playerItem.error.domain},
|
||||
@"target": self.reactTag}];
|
||||
}
|
||||
} else if ([keyPath isEqualToString:playbackBufferEmptyKeyPath]) {
|
||||
_playerBufferEmpty = YES;
|
||||
} else if ([keyPath isEqualToString:playbackLikelyToKeepUpKeyPath]) {
|
||||
// Continue playing (or not if paused) after being paused due to hitting an unbuffered zone.
|
||||
if ((!(_controls || _fullscreenPlayerPresented) || _playerBufferEmpty) && _playerItem.playbackLikelyToKeepUp) {
|
||||
[self setPaused:_paused];
|
||||
}
|
||||
_playerBufferEmpty = NO;
|
||||
}
|
||||
} else if (object == _playerLayer) {
|
||||
if([keyPath isEqualToString:readyForDisplayKeyPath] && [change objectForKey:NSKeyValueChangeNewKey]) {
|
||||
if([change objectForKey:NSKeyValueChangeNewKey]) {
|
||||
[_eventDispatcher sendInputEventWithName:@"onReadyForDisplay"
|
||||
body:@{@"target": self.reactTag}];
|
||||
}
|
||||
}
|
||||
} else if (object == _player) {
|
||||
if([keyPath isEqualToString:playbackRate]) {
|
||||
[_eventDispatcher sendInputEventWithName:@"onPlaybackRateChange"
|
||||
body:@{@"playbackRate": [NSNumber numberWithFloat:_player.rate],
|
||||
@"target": self.reactTag}];
|
||||
if(_playbackStalled && _player.rate > 0) {
|
||||
[_eventDispatcher sendInputEventWithName:@"onPlaybackResume"
|
||||
body:@{@"playbackRate": [NSNumber numberWithFloat:_player.rate],
|
||||
@"target": self.reactTag}];
|
||||
_playbackStalled = NO;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)attachListeners
|
||||
{
|
||||
// listen for end of file
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(playerItemDidReachEnd:)
|
||||
name:AVPlayerItemDidPlayToEndTimeNotification
|
||||
object:[_player currentItem]];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(playbackStalled:)
|
||||
name:AVPlayerItemPlaybackStalledNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)playbackStalled:(NSNotification *)notification
|
||||
{
|
||||
[_eventDispatcher sendInputEventWithName:@"onPlaybackStalled" body:@{@"target": self.reactTag}];
|
||||
_playbackStalled = YES;
|
||||
}
|
||||
|
||||
- (void)playerItemDidReachEnd:(NSNotification *)notification
|
||||
{
|
||||
[_eventDispatcher sendInputEventWithName:@"onVideoEnd" body:@{@"target": self.reactTag}];
|
||||
|
||||
if (_repeat) {
|
||||
AVPlayerItem *item = [notification object];
|
||||
[item seekToTime:kCMTimeZero];
|
||||
[self applyModifiers];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Prop setters
|
||||
|
||||
- (void)setResizeMode:(NSString*)mode
|
||||
{
|
||||
if( _controls )
|
||||
{
|
||||
_playerViewController.videoGravity = mode;
|
||||
}
|
||||
else
|
||||
{
|
||||
_playerLayer.videoGravity = mode;
|
||||
}
|
||||
_resizeMode = mode;
|
||||
}
|
||||
|
||||
- (void)setPlayInBackground:(BOOL)playInBackground
|
||||
{
|
||||
_playInBackground = playInBackground;
|
||||
}
|
||||
|
||||
- (void)setPlayWhenInactive:(BOOL)playWhenInactive
|
||||
{
|
||||
_playWhenInactive = playWhenInactive;
|
||||
}
|
||||
|
||||
- (void)setPaused:(BOOL)paused
|
||||
{
|
||||
if (paused) {
|
||||
[_player pause];
|
||||
[_player setRate:0.0];
|
||||
} else {
|
||||
[_player play];
|
||||
[_player setRate:_rate];
|
||||
}
|
||||
|
||||
_paused = paused;
|
||||
}
|
||||
|
||||
- (float)getCurrentTime
|
||||
{
|
||||
return _playerItem != NULL ? CMTimeGetSeconds(_playerItem.currentTime) : 0;
|
||||
}
|
||||
|
||||
- (void)setCurrentTime:(float)currentTime
|
||||
{
|
||||
[self setSeek: currentTime];
|
||||
}
|
||||
|
||||
- (void)setSeek:(float)seekTime
|
||||
{
|
||||
int timeScale = 10000;
|
||||
|
||||
AVPlayerItem *item = _player.currentItem;
|
||||
if (item && item.status == AVPlayerItemStatusReadyToPlay) {
|
||||
// TODO check loadedTimeRanges
|
||||
|
||||
CMTime cmSeekTime = CMTimeMakeWithSeconds(seekTime, timeScale);
|
||||
CMTime current = item.currentTime;
|
||||
// TODO figure out a good tolerance level
|
||||
CMTime tolerance = CMTimeMake(1000, timeScale);
|
||||
|
||||
if (CMTimeCompare(current, cmSeekTime) != 0) {
|
||||
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
|
||||
[_eventDispatcher sendInputEventWithName:@"onVideoSeek"
|
||||
body:@{@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
|
||||
@"seekTime": [NSNumber numberWithFloat:seekTime],
|
||||
@"target": self.reactTag}];
|
||||
}];
|
||||
|
||||
_pendingSeek = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
// TODO: See if this makes sense and if so, actually implement it
|
||||
_pendingSeek = true;
|
||||
_pendingSeekTime = seekTime;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setRate:(float)rate
|
||||
{
|
||||
_rate = rate;
|
||||
[self applyModifiers];
|
||||
}
|
||||
|
||||
- (void)setMuted:(BOOL)muted
|
||||
{
|
||||
_muted = muted;
|
||||
[self applyModifiers];
|
||||
}
|
||||
|
||||
- (void)setVolume:(float)volume
|
||||
{
|
||||
_volume = volume;
|
||||
[self applyModifiers];
|
||||
}
|
||||
|
||||
- (void)applyModifiers
|
||||
{
|
||||
if (_muted) {
|
||||
[_player setVolume:0];
|
||||
[_player setMuted:YES];
|
||||
} else {
|
||||
[_player setVolume:_volume];
|
||||
[_player setMuted:NO];
|
||||
}
|
||||
|
||||
[self setResizeMode:_resizeMode];
|
||||
[self setRepeat:_repeat];
|
||||
[self setPaused:_paused];
|
||||
[self setControls:_controls];
|
||||
}
|
||||
|
||||
- (void)setRepeat:(BOOL)repeat {
|
||||
_repeat = repeat;
|
||||
}
|
||||
|
||||
- (BOOL)getFullscreen
|
||||
{
|
||||
return _fullscreenPlayerPresented;
|
||||
}
|
||||
|
||||
- (void)setFullscreen:(BOOL)fullscreen
|
||||
{
|
||||
if( fullscreen && !_fullscreenPlayerPresented )
|
||||
{
|
||||
// Ensure player view controller is not null
|
||||
if( !_playerViewController )
|
||||
{
|
||||
[self usePlayerViewController];
|
||||
}
|
||||
// Set presentation style to fullscreen
|
||||
[_playerViewController setModalPresentationStyle:UIModalPresentationFullScreen];
|
||||
|
||||
// Find the nearest view controller
|
||||
UIViewController *viewController = [self firstAvailableUIViewController];
|
||||
if( !viewController )
|
||||
{
|
||||
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
|
||||
viewController = keyWindow.rootViewController;
|
||||
if( viewController.childViewControllers.count > 0 )
|
||||
{
|
||||
viewController = viewController.childViewControllers.lastObject;
|
||||
}
|
||||
}
|
||||
if( viewController )
|
||||
{
|
||||
_presentingViewController = viewController;
|
||||
[_eventDispatcher sendInputEventWithName:@"onVideoFullscreenPlayerWillPresent" body:@{@"target": self.reactTag}];
|
||||
[viewController presentViewController:_playerViewController animated:true completion:^{
|
||||
_playerViewController.showsPlaybackControls = YES;
|
||||
_fullscreenPlayerPresented = fullscreen;
|
||||
[_eventDispatcher sendInputEventWithName:@"onVideoFullscreenPlayerDidPresent" body:@{@"target": self.reactTag}];
|
||||
}];
|
||||
}
|
||||
}
|
||||
else if ( !fullscreen && _fullscreenPlayerPresented )
|
||||
{
|
||||
[self videoPlayerViewControllerWillDismiss:_playerViewController];
|
||||
[_presentingViewController dismissViewControllerAnimated:true completion:^{
|
||||
[self videoPlayerViewControllerDidDismiss:_playerViewController];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)usePlayerViewController
|
||||
{
|
||||
if( _player )
|
||||
{
|
||||
_playerViewController = [self createPlayerViewController:_player withPlayerItem:_playerItem];
|
||||
// to prevent video from being animated when resizeMode is 'cover'
|
||||
// resize mode must be set before subview is added
|
||||
[self setResizeMode:_resizeMode];
|
||||
[self addSubview:_playerViewController.view];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)usePlayerLayer
|
||||
{
|
||||
if( _player )
|
||||
{
|
||||
_playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
|
||||
_playerLayer.frame = self.bounds;
|
||||
_playerLayer.needsDisplayOnBoundsChange = YES;
|
||||
|
||||
// to prevent video from being animated when resizeMode is 'cover'
|
||||
// resize mode must be set before layer is added
|
||||
[self setResizeMode:_resizeMode];
|
||||
[_playerLayer addObserver:self forKeyPath:readyForDisplayKeyPath options:NSKeyValueObservingOptionNew context:nil];
|
||||
|
||||
[self.layer addSublayer:_playerLayer];
|
||||
self.layer.needsDisplayOnBoundsChange = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setControls:(BOOL)controls
|
||||
{
|
||||
if( _controls != controls || (!_playerLayer && !_playerViewController) )
|
||||
{
|
||||
_controls = controls;
|
||||
if( _controls )
|
||||
{
|
||||
[self removePlayerLayer];
|
||||
[self usePlayerViewController];
|
||||
}
|
||||
else
|
||||
{
|
||||
[_playerViewController.view removeFromSuperview];
|
||||
_playerViewController = nil;
|
||||
[self usePlayerLayer];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removePlayerLayer
|
||||
{
|
||||
[_playerLayer removeFromSuperlayer];
|
||||
[_playerLayer removeObserver:self forKeyPath:readyForDisplayKeyPath];
|
||||
_playerLayer = nil;
|
||||
}
|
||||
|
||||
#pragma mark - RCTVideoPlayerViewControllerDelegate
|
||||
|
||||
- (void)videoPlayerViewControllerWillDismiss:(AVPlayerViewController *)playerViewController
|
||||
{
|
||||
if (_playerViewController == playerViewController && _fullscreenPlayerPresented)
|
||||
{
|
||||
[_eventDispatcher sendInputEventWithName:@"onVideoFullscreenPlayerWillDismiss" body:@{@"target": self.reactTag}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)videoPlayerViewControllerDidDismiss:(AVPlayerViewController *)playerViewController
|
||||
{
|
||||
if (_playerViewController == playerViewController && _fullscreenPlayerPresented)
|
||||
{
|
||||
_fullscreenPlayerPresented = false;
|
||||
_presentingViewController = nil;
|
||||
[self applyModifiers];
|
||||
[_eventDispatcher sendInputEventWithName:@"onVideoFullscreenPlayerDidDismiss" body:@{@"target": self.reactTag}];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - React View Management
|
||||
|
||||
- (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex
|
||||
{
|
||||
// We are early in the game and somebody wants to set a subview.
|
||||
// That can only be in the context of playerViewController.
|
||||
if( !_controls && !_playerLayer && !_playerViewController )
|
||||
{
|
||||
[self setControls:true];
|
||||
}
|
||||
|
||||
if( _controls )
|
||||
{
|
||||
view.frame = self.bounds;
|
||||
[_playerViewController.contentOverlayView insertSubview:view atIndex:atIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
RCTLogError(@"video cannot have any subviews");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
- (void)removeReactSubview:(UIView *)subview
|
||||
{
|
||||
if( _controls )
|
||||
{
|
||||
[subview removeFromSuperview];
|
||||
}
|
||||
else
|
||||
{
|
||||
RCTLogError(@"video cannot have any subviews");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
if( _controls )
|
||||
{
|
||||
_playerViewController.view.frame = self.bounds;
|
||||
|
||||
// also adjust all subviews of contentOverlayView
|
||||
for (UIView* subview in _playerViewController.contentOverlayView.subviews) {
|
||||
subview.frame = self.bounds;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[CATransaction begin];
|
||||
[CATransaction setAnimationDuration:0];
|
||||
_playerLayer.frame = self.bounds;
|
||||
[CATransaction commit];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
- (void)removeFromSuperview
|
||||
{
|
||||
[_player pause];
|
||||
if (_playbackRateObserverRegistered) {
|
||||
[_player removeObserver:self forKeyPath:playbackRate context:nil];
|
||||
_playbackRateObserverRegistered = NO;
|
||||
}
|
||||
_player = nil;
|
||||
|
||||
[self removePlayerLayer];
|
||||
|
||||
[_playerViewController.view removeFromSuperview];
|
||||
_playerViewController = nil;
|
||||
|
||||
[self removePlayerTimeObserver];
|
||||
[self removePlayerItemObservers];
|
||||
|
||||
_eventDispatcher = nil;
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
[super removeFromSuperview];
|
||||
}
|
||||
|
||||
@end
|
273
ios/RCTVideo.xcodeproj/project.pbxproj
Normal file
273
ios/RCTVideo.xcodeproj/project.pbxproj
Normal file
@@ -0,0 +1,273 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
31CAFB211CADA8CD009BCF6F /* UIView+FindUIViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 31CAFB201CADA8CD009BCF6F /* UIView+FindUIViewController.m */; };
|
||||
31CAFB2F1CADC77F009BCF6F /* RCTVideoPlayerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 31CAFB2E1CADC77F009BCF6F /* RCTVideoPlayerViewController.m */; };
|
||||
BBD49E3F1AC8DEF000610F8E /* RCTVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = BBD49E3A1AC8DEF000610F8E /* RCTVideo.m */; };
|
||||
BBD49E401AC8DEF000610F8E /* RCTVideoManager.m in Sources */ = {isa = PBXBuildFile; fileRef = BBD49E3C1AC8DEF000610F8E /* RCTVideoManager.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
58B511D91A9E6C8500147676 /* CopyFiles */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = "include/$(PRODUCT_NAME)";
|
||||
dstSubfolderSpec = 16;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
134814201AA4EA6300B7C361 /* libRCTVideo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTVideo.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
31CAFB1F1CADA8CD009BCF6F /* UIView+FindUIViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+FindUIViewController.h"; sourceTree = "<group>"; };
|
||||
31CAFB201CADA8CD009BCF6F /* UIView+FindUIViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+FindUIViewController.m"; sourceTree = "<group>"; };
|
||||
31CAFB2D1CADC77F009BCF6F /* RCTVideoPlayerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTVideoPlayerViewController.h; sourceTree = "<group>"; };
|
||||
31CAFB2E1CADC77F009BCF6F /* RCTVideoPlayerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVideoPlayerViewController.m; sourceTree = "<group>"; };
|
||||
31CAFB301CAE6B5F009BCF6F /* RCTVideoPlayerViewControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTVideoPlayerViewControllerDelegate.h; sourceTree = "<group>"; };
|
||||
BBD49E391AC8DEF000610F8E /* RCTVideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTVideo.h; sourceTree = "<group>"; };
|
||||
BBD49E3A1AC8DEF000610F8E /* RCTVideo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVideo.m; sourceTree = "<group>"; };
|
||||
BBD49E3B1AC8DEF000610F8E /* RCTVideoManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTVideoManager.h; sourceTree = "<group>"; };
|
||||
BBD49E3C1AC8DEF000610F8E /* RCTVideoManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVideoManager.m; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
58B511D81A9E6C8500147676 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
134814211AA4EA7D00B7C361 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
134814201AA4EA6300B7C361 /* libRCTVideo.a */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
58B511D21A9E6C8500147676 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
BBD49E391AC8DEF000610F8E /* RCTVideo.h */,
|
||||
BBD49E3A1AC8DEF000610F8E /* RCTVideo.m */,
|
||||
31CAFB301CAE6B5F009BCF6F /* RCTVideoPlayerViewControllerDelegate.h */,
|
||||
31CAFB2D1CADC77F009BCF6F /* RCTVideoPlayerViewController.h */,
|
||||
31CAFB2E1CADC77F009BCF6F /* RCTVideoPlayerViewController.m */,
|
||||
BBD49E3B1AC8DEF000610F8E /* RCTVideoManager.h */,
|
||||
BBD49E3C1AC8DEF000610F8E /* RCTVideoManager.m */,
|
||||
31CAFB1F1CADA8CD009BCF6F /* UIView+FindUIViewController.h */,
|
||||
31CAFB201CADA8CD009BCF6F /* UIView+FindUIViewController.m */,
|
||||
134814211AA4EA7D00B7C361 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
58B511DA1A9E6C8500147676 /* RCTVideo */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTVideo" */;
|
||||
buildPhases = (
|
||||
58B511D71A9E6C8500147676 /* Sources */,
|
||||
58B511D81A9E6C8500147676 /* Frameworks */,
|
||||
58B511D91A9E6C8500147676 /* CopyFiles */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = RCTVideo;
|
||||
productName = RCTDataManager;
|
||||
productReference = 134814201AA4EA6300B7C361 /* libRCTVideo.a */;
|
||||
productType = "com.apple.product-type.library.static";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
58B511D31A9E6C8500147676 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0720;
|
||||
ORGANIZATIONNAME = Facebook;
|
||||
TargetAttributes = {
|
||||
58B511DA1A9E6C8500147676 = {
|
||||
CreatedOnToolsVersion = 6.1.1;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTVideo" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
);
|
||||
mainGroup = 58B511D21A9E6C8500147676;
|
||||
productRefGroup = 58B511D21A9E6C8500147676;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
58B511DA1A9E6C8500147676 /* RCTVideo */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
58B511D71A9E6C8500147676 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
31CAFB211CADA8CD009BCF6F /* UIView+FindUIViewController.m in Sources */,
|
||||
31CAFB2F1CADC77F009BCF6F /* RCTVideoPlayerViewController.m in Sources */,
|
||||
BBD49E3F1AC8DEF000610F8E /* RCTVideo.m in Sources */,
|
||||
BBD49E401AC8DEF000610F8E /* RCTVideoManager.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
58B511ED1A9E6C8500147676 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
58B511EE1A9E6C8500147676 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = YES;
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
58B511F01A9E6C8500147676 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
||||
"$(SRCROOT)/../../react-native/React/**",
|
||||
"$(SRCROOT)/../node_modules/react-native/React/**",
|
||||
);
|
||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PRODUCT_NAME = RCTVideo;
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
58B511F11A9E6C8500147676 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
||||
"$(SRCROOT)/../../react-native/React/**",
|
||||
"$(SRCROOT)/../node_modules/react-native/React/**",
|
||||
);
|
||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PRODUCT_NAME = RCTVideo;
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTVideo" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
58B511ED1A9E6C8500147676 /* Debug */,
|
||||
58B511EE1A9E6C8500147676 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTVideo" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
58B511F01A9E6C8500147676 /* Debug */,
|
||||
58B511F11A9E6C8500147676 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 58B511D31A9E6C8500147676 /* Project object */;
|
||||
}
|
5
ios/RCTVideoManager.h
Normal file
5
ios/RCTVideoManager.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#import "RCTViewManager.h"
|
||||
|
||||
@interface RCTVideoManager : RCTViewManager
|
||||
|
||||
@end
|
68
ios/RCTVideoManager.m
Normal file
68
ios/RCTVideoManager.m
Normal file
@@ -0,0 +1,68 @@
|
||||
#import "RCTVideoManager.h"
|
||||
#import "RCTVideo.h"
|
||||
#import "RCTBridge.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
@implementation RCTVideoManager
|
||||
|
||||
RCT_EXPORT_MODULE();
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
|
||||
- (UIView *)view
|
||||
{
|
||||
return [[RCTVideo alloc] initWithEventDispatcher:self.bridge.eventDispatcher];
|
||||
}
|
||||
|
||||
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
|
||||
|
||||
- (NSArray *)customDirectEventTypes
|
||||
{
|
||||
return @[
|
||||
@"onVideoLoadStart",
|
||||
@"onVideoLoad",
|
||||
@"onVideoError",
|
||||
@"onVideoProgress",
|
||||
@"onVideoSeek",
|
||||
@"onVideoEnd",
|
||||
@"onVideoFullscreenPlayerWillPresent",
|
||||
@"onVideoFullscreenPlayerDidPresent",
|
||||
@"onVideoFullscreenPlayerWillDismiss",
|
||||
@"onVideoFullscreenPlayerDidDismiss",
|
||||
@"onReadyForDisplay",
|
||||
@"onPlaybackStalled",
|
||||
@"onPlaybackResume",
|
||||
@"onPlaybackRateChange"
|
||||
];
|
||||
}
|
||||
|
||||
- (dispatch_queue_t)methodQueue
|
||||
{
|
||||
return dispatch_get_main_queue();
|
||||
}
|
||||
|
||||
RCT_EXPORT_VIEW_PROPERTY(src, NSDictionary);
|
||||
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(paused, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(muted, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(controls, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(volume, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(playInBackground, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(playWhenInactive, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(rate, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(seek, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(currentTime, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(fullscreen, BOOL);
|
||||
|
||||
- (NSDictionary *)constantsToExport
|
||||
{
|
||||
return @{
|
||||
@"ScaleNone": AVLayerVideoGravityResizeAspect,
|
||||
@"ScaleToFill": AVLayerVideoGravityResize,
|
||||
@"ScaleAspectFit": AVLayerVideoGravityResizeAspect,
|
||||
@"ScaleAspectFill": AVLayerVideoGravityResizeAspectFill
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
15
ios/RCTVideoPlayerViewController.h
Normal file
15
ios/RCTVideoPlayerViewController.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// RCTVideoPlayerViewController.h
|
||||
// RCTVideo
|
||||
//
|
||||
// Created by Stanisław Chmiela on 31.03.2016.
|
||||
// Copyright © 2016 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
#import <AVKit/AVKit.h>
|
||||
#import "RCTVideo.h"
|
||||
#import "RCTVideoPlayerViewControllerDelegate.h"
|
||||
|
||||
@interface RCTVideoPlayerViewController : AVPlayerViewController
|
||||
@property (nonatomic, weak) id<RCTVideoPlayerViewControllerDelegate> rctDelegate;
|
||||
@end
|
20
ios/RCTVideoPlayerViewController.m
Normal file
20
ios/RCTVideoPlayerViewController.m
Normal file
@@ -0,0 +1,20 @@
|
||||
#import "RCTVideoPlayerViewController.h"
|
||||
|
||||
@interface RCTVideoPlayerViewController ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTVideoPlayerViewController
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewDidDisappear:animated];
|
||||
[_rctDelegate videoPlayerViewControllerDidDismiss:self];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[_rctDelegate videoPlayerViewControllerWillDismiss:self];
|
||||
[super viewWillDisappear:animated];
|
||||
}
|
||||
|
||||
@end
|
7
ios/RCTVideoPlayerViewControllerDelegate.h
Normal file
7
ios/RCTVideoPlayerViewControllerDelegate.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "AVKit/AVKit.h"
|
||||
|
||||
@protocol RCTVideoPlayerViewControllerDelegate <NSObject>
|
||||
- (void)videoPlayerViewControllerWillDismiss:(AVPlayerViewController *)playerViewController;
|
||||
- (void)videoPlayerViewControllerDidDismiss:(AVPlayerViewController *)playerViewController;
|
||||
@end
|
15
ios/UIView+FindUIViewController.h
Normal file
15
ios/UIView+FindUIViewController.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// UIView+FindUIViewController.h
|
||||
// RCTVideo
|
||||
//
|
||||
// Created by Stanisław Chmiela on 31.03.2016.
|
||||
// Copyright © 2016 Facebook. All rights reserved.
|
||||
//
|
||||
// Source: http://stackoverflow.com/a/3732812/1123156
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface UIView (FindUIViewController)
|
||||
- (UIViewController *) firstAvailableUIViewController;
|
||||
- (id) traverseResponderChainForUIViewController;
|
||||
@end
|
21
ios/UIView+FindUIViewController.m
Normal file
21
ios/UIView+FindUIViewController.m
Normal file
@@ -0,0 +1,21 @@
|
||||
// Source: http://stackoverflow.com/a/3732812/1123156
|
||||
|
||||
#import "UIView+FindUIViewController.h"
|
||||
|
||||
@implementation UIView (FindUIViewController)
|
||||
- (UIViewController *) firstAvailableUIViewController {
|
||||
// convenience function for casting and to "mask" the recursive function
|
||||
return (UIViewController *)[self traverseResponderChainForUIViewController];
|
||||
}
|
||||
|
||||
- (id) traverseResponderChainForUIViewController {
|
||||
id nextResponder = [self nextResponder];
|
||||
if ([nextResponder isKindOfClass:[UIViewController class]]) {
|
||||
return nextResponder;
|
||||
} else if ([nextResponder isKindOfClass:[UIView class]]) {
|
||||
return [nextResponder traverseResponderChainForUIViewController];
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
@end
|
Reference in New Issue
Block a user