Merge branch 'master' of git://github.com/react-native-community/react-native-video into react-native-community-master
Merge branch 'master' of git://github.com/react-native-community/react-native-video into react-native-community-master
This commit is contained in:
45
ios/Video/RCTVideo.h
Normal file
45
ios/Video/RCTVideo.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import "AVKit/AVKit.h"
|
||||
#import "UIView+FindUIViewController.h"
|
||||
#import "RCTVideoPlayerViewController.h"
|
||||
#import "RCTVideoPlayerViewControllerDelegate.h"
|
||||
#import <React/RCTComponent.h>
|
||||
|
||||
#if __has_include(<react-native-video/RCTVideoCache.h>)
|
||||
#import <react-native-video/RCTVideoCache.h>
|
||||
#import <DVAssetLoaderDelegate/DVURLAsset.h>
|
||||
#import <DVAssetLoaderDelegate/DVAssetLoaderDelegate.h>
|
||||
#endif
|
||||
|
||||
@class RCTEventDispatcher;
|
||||
#if __has_include(<react-native-video/RCTVideoCache.h>)
|
||||
@interface RCTVideo : UIView <RCTVideoPlayerViewControllerDelegate, DVAssetLoaderDelegatesDelegate>
|
||||
#else
|
||||
@interface RCTVideo : UIView <RCTVideoPlayerViewControllerDelegate>
|
||||
#endif
|
||||
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoLoadStart;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoLoad;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoBuffer;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoError;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoProgress;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onBandwidthUpdate;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoSeek;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoEnd;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onTimedMetadata;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoAudioBecomingNoisy;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoFullscreenPlayerWillPresent;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoFullscreenPlayerDidPresent;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoFullscreenPlayerWillDismiss;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoFullscreenPlayerDidDismiss;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onReadyForDisplay;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onPlaybackStalled;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onPlaybackResume;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onPlaybackRateChange;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoExternalPlaybackChange;
|
||||
|
||||
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem;
|
||||
|
||||
@end
|
1359
ios/Video/RCTVideo.m
Normal file
1359
ios/Video/RCTVideo.m
Normal file
File diff suppressed because it is too large
Load Diff
5
ios/Video/RCTVideoManager.h
Normal file
5
ios/Video/RCTVideoManager.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#import <React/RCTViewManager.h>
|
||||
|
||||
@interface RCTVideoManager : RCTViewManager
|
||||
|
||||
@end
|
78
ios/Video/RCTVideoManager.m
Normal file
78
ios/Video/RCTVideoManager.m
Normal file
@@ -0,0 +1,78 @@
|
||||
#import "RCTVideoManager.h"
|
||||
#import "RCTVideo.h"
|
||||
#import <React/RCTBridge.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
@implementation RCTVideoManager
|
||||
|
||||
RCT_EXPORT_MODULE();
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
|
||||
- (UIView *)view
|
||||
{
|
||||
return [[RCTVideo alloc] initWithEventDispatcher:self.bridge.eventDispatcher];
|
||||
}
|
||||
|
||||
- (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(allowsExternalPlayback, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(textTracks, NSArray);
|
||||
RCT_EXPORT_VIEW_PROPERTY(selectedTextTrack, NSDictionary);
|
||||
RCT_EXPORT_VIEW_PROPERTY(selectedAudioTrack, NSDictionary);
|
||||
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(ignoreSilentSwitch, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(rate, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary);
|
||||
RCT_EXPORT_VIEW_PROPERTY(currentTime, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(fullscreen, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(fullscreenOrientation, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(progressUpdateInterval, float);
|
||||
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoLoad, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoBuffer, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoError, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoProgress, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onBandwidthUpdate, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoSeek, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoEnd, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onTimedMetadata, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoAudioBecomingNoisy, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerWillPresent, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerDidPresent, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerWillDismiss, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerDidDismiss, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onReadyForDisplay, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onPlaybackStalled, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onPlaybackResume, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onPlaybackRateChange, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoExternalPlaybackChange, RCTBubblingEventBlock);
|
||||
|
||||
- (NSDictionary *)constantsToExport
|
||||
{
|
||||
return @{
|
||||
@"ScaleNone": AVLayerVideoGravityResizeAspect,
|
||||
@"ScaleToFill": AVLayerVideoGravityResize,
|
||||
@"ScaleAspectFit": AVLayerVideoGravityResizeAspect,
|
||||
@"ScaleAspectFill": AVLayerVideoGravityResizeAspectFill
|
||||
};
|
||||
}
|
||||
|
||||
+ (BOOL)requiresMainQueueSetup
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
19
ios/Video/RCTVideoPlayerViewController.h
Normal file
19
ios/Video/RCTVideoPlayerViewController.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// 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;
|
||||
|
||||
// Optional paramters
|
||||
@property (nonatomic, weak) NSString* preferredOrientation;
|
||||
|
||||
@end
|
42
ios/Video/RCTVideoPlayerViewController.m
Normal file
42
ios/Video/RCTVideoPlayerViewController.m
Normal file
@@ -0,0 +1,42 @@
|
||||
#import "RCTVideoPlayerViewController.h"
|
||||
|
||||
@interface RCTVideoPlayerViewController ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTVideoPlayerViewController
|
||||
|
||||
- (BOOL)shouldAutorotate {
|
||||
if (self.preferredOrientation.lowercaseString == nil || [self.preferredOrientation.lowercaseString isEqualToString:@"all"])
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewDidDisappear:animated];
|
||||
[_rctDelegate videoPlayerViewControllerWillDismiss:self];
|
||||
[_rctDelegate videoPlayerViewControllerDidDismiss:self];
|
||||
}
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
|
||||
return UIInterfaceOrientationMaskAll;
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
|
||||
if ([self.preferredOrientation.lowercaseString isEqualToString:@"landscape"]) {
|
||||
return UIInterfaceOrientationLandscapeRight;
|
||||
}
|
||||
else if ([self.preferredOrientation.lowercaseString isEqualToString:@"portrait"]) {
|
||||
return UIInterfaceOrientationPortrait;
|
||||
}
|
||||
else { // default case
|
||||
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
||||
return orientation;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
7
ios/Video/RCTVideoPlayerViewControllerDelegate.h
Normal file
7
ios/Video/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/Video/UIView+FindUIViewController.h
Normal file
15
ios/Video/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/Video/UIView+FindUIViewController.m
Normal file
21
ios/Video/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