Add cache property; Make playerItemForSource in 'RCTVideoManager.m' async
This commit is contained in:
parent
6b2c1046dd
commit
438aa79494
1
Video.js
1
Video.js
@ -247,6 +247,7 @@ export default class Video extends Component {
|
|||||||
Video.propTypes = {
|
Video.propTypes = {
|
||||||
/* Native only */
|
/* Native only */
|
||||||
src: PropTypes.object,
|
src: PropTypes.object,
|
||||||
|
cache: PropTypes.bool,
|
||||||
seek: PropTypes.number,
|
seek: PropTypes.number,
|
||||||
fullscreen: PropTypes.bool,
|
fullscreen: PropTypes.bool,
|
||||||
onVideoLoadStart: PropTypes.func,
|
onVideoLoadStart: PropTypes.func,
|
||||||
|
@ -266,11 +266,23 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
|
|
||||||
#pragma mark - Player and source
|
#pragma mark - Player and source
|
||||||
|
|
||||||
|
- (void)setCache:(BOOL *)cache
|
||||||
|
{
|
||||||
|
// @TODO: Implement
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setSrc:(NSDictionary *)source
|
- (void)setSrc:(NSDictionary *)source
|
||||||
{
|
{
|
||||||
[self removePlayerTimeObserver];
|
[self removePlayerTimeObserver];
|
||||||
[self removePlayerItemObservers];
|
[self removePlayerItemObservers];
|
||||||
_playerItem = [self playerItemForSource:source];
|
[self playerItemForSource:source withCallback:^(AVPlayerItem * playerItem) {
|
||||||
|
[self didSetPlayerItemWithSource:source playerItem:playerItem];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) didSetPlayerItemWithSource:(NSDictionary *)source playerItem:(AVPlayerItem *) playerItem
|
||||||
|
{
|
||||||
|
_playerItem = playerItem;
|
||||||
[self addPlayerItemObservers];
|
[self addPlayerItemObservers];
|
||||||
|
|
||||||
[_player pause];
|
[_player pause];
|
||||||
@ -312,7 +324,7 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (AVPlayerItem*)playerItemForSource:(NSDictionary *)source
|
- (void)playerItemForSource:(NSDictionary *)source withCallback:(void(^)(AVPlayerItem *))handler
|
||||||
{
|
{
|
||||||
bool isNetwork = [RCTConvert BOOL:[source objectForKey:@"isNetwork"]];
|
bool isNetwork = [RCTConvert BOOL:[source objectForKey:@"isNetwork"]];
|
||||||
bool isAsset = [RCTConvert BOOL:[source objectForKey:@"isAsset"]];
|
bool isAsset = [RCTConvert BOOL:[source objectForKey:@"isAsset"]];
|
||||||
@ -324,16 +336,19 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]];
|
[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]];
|
||||||
|
|
||||||
if (isNetwork) {
|
if (isNetwork) {
|
||||||
|
// @TODO: Check if item is cached an if so use the cached asset
|
||||||
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
|
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
|
||||||
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:@{AVURLAssetHTTPCookiesKey : cookies}];
|
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:@{AVURLAssetHTTPCookiesKey : cookies}];
|
||||||
return [AVPlayerItem playerItemWithAsset:asset];
|
handler([AVPlayerItem playerItemWithAsset:asset]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (isAsset) {
|
else if (isAsset) {
|
||||||
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
|
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
|
||||||
return [AVPlayerItem playerItemWithAsset:asset];
|
handler([AVPlayerItem playerItemWithAsset:asset]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
handler([AVPlayerItem playerItemWithURL:url]);
|
||||||
return [AVPlayerItem playerItemWithURL:url];
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||||
|
@ -20,6 +20,7 @@ RCT_EXPORT_MODULE();
|
|||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_VIEW_PROPERTY(src, NSDictionary);
|
RCT_EXPORT_VIEW_PROPERTY(src, NSDictionary);
|
||||||
|
RCT_EXPORT_VIEW_PROPERTY(cache, BOOL);
|
||||||
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
|
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
|
||||||
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL);
|
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL);
|
||||||
RCT_EXPORT_VIEW_PROPERTY(paused, BOOL);
|
RCT_EXPORT_VIEW_PROPERTY(paused, BOOL);
|
||||||
|
Loading…
Reference in New Issue
Block a user