fix: 🐛 support ios cameraroll
This commit is contained in:
parent
63f12eaed6
commit
285e9ca881
2
Video.js
2
Video.js
@ -275,7 +275,7 @@ export default class Video extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isNetwork = !!(uri && uri.match(/^https?:/));
|
const isNetwork = !!(uri && uri.match(/^https?:/));
|
||||||
const isAsset = !!(uri && uri.match(/^(assets-library|ipod-library|file|content|ms-appx|ms-appdata):/));
|
const isAsset = !!(uri && uri.match(/^(assets-library|ph|ipod-library|file|content|ms-appx|ms-appdata):/));
|
||||||
|
|
||||||
let nativeResizeMode;
|
let nativeResizeMode;
|
||||||
const RCTVideoInstance = this.getViewManagerConfig('RCTVideo');
|
const RCTVideoInstance = this.getViewManagerConfig('RCTVideo');
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#import <React/UIView+React.h>
|
#import <React/UIView+React.h>
|
||||||
#include <MediaAccessibility/MediaAccessibility.h>
|
#include <MediaAccessibility/MediaAccessibility.h>
|
||||||
#include <AVFoundation/AVFoundation.h>
|
#include <AVFoundation/AVFoundation.h>
|
||||||
|
#import <Photos/Photos.h>
|
||||||
|
|
||||||
static NSString *const statusKeyPath = @"status";
|
static NSString *const statusKeyPath = @"status";
|
||||||
static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp";
|
static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp";
|
||||||
@ -492,22 +493,22 @@ static int const RCTVideoUnset = -1;
|
|||||||
handler([AVPlayerItem playerItemWithAsset:mixComposition]);
|
handler([AVPlayerItem playerItemWithAsset:mixComposition]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playerItemForSource:(NSDictionary *)source withCallback:(void(^)(AVPlayerItem *))handler
|
- (void)loadAssetFromSource:(NSDictionary *)source withCallback:(void(^)(AVURLAsset *asset, NSMutableDictionary *assetOptions)) 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"]];
|
||||||
bool shouldCache = [RCTConvert BOOL:[source objectForKey:@"shouldCache"]];
|
bool shouldCache = [RCTConvert BOOL:[source objectForKey:@"shouldCache"]];
|
||||||
|
|
||||||
NSString *uri = [source objectForKey:@"uri"];
|
NSString *uri = [source objectForKey:@"uri"];
|
||||||
NSString *type = [source objectForKey:@"type"];
|
NSString *type = [source objectForKey:@"type"];
|
||||||
AVURLAsset *asset;
|
|
||||||
if (!uri || [uri isEqualToString:@""]) {
|
if (!uri || [uri isEqualToString:@""]) {
|
||||||
DebugLog(@"Could not find video URL in source '%@'", source);
|
DebugLog(@"Could not find video URL in source '%@'", source);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSURL *url = isNetwork || isAsset
|
NSURL *url = isNetwork || isAsset
|
||||||
? [NSURL URLWithString:uri]
|
? [NSURL URLWithString:uri]
|
||||||
: [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]];
|
: [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]];
|
||||||
NSMutableDictionary *assetOptions = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *assetOptions = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
if (isNetwork) {
|
if (isNetwork) {
|
||||||
@ -529,26 +530,43 @@ static int const RCTVideoUnset = -1;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
handler([AVURLAsset URLAssetWithURL:url options:assetOptions], assetOptions);
|
||||||
asset = [AVURLAsset URLAssetWithURL:url options:assetOptions];
|
|
||||||
} else if (isAsset) {
|
} else if (isAsset) {
|
||||||
asset = [AVURLAsset URLAssetWithURL:url options:nil];
|
if ([uri hasPrefix:@"ph://"]) {
|
||||||
} else {
|
NSString *assetId = [uri substringFromIndex:@"ph://".length];
|
||||||
asset = [AVURLAsset URLAssetWithURL:[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]] options:nil];
|
PHAsset *asset = [[PHAsset fetchAssetsWithLocalIdentifiers:@[assetId] options:nil] firstObject];
|
||||||
}
|
PHVideoRequestOptions *options = [PHVideoRequestOptions new];
|
||||||
// Reset _loadingRequest
|
options.networkAccessAllowed = YES;
|
||||||
if (_loadingRequest != nil) {
|
|
||||||
[_loadingRequest finishLoading];
|
|
||||||
}
|
|
||||||
_requestingCertificate = NO;
|
|
||||||
_requestingCertificateErrored = NO;
|
|
||||||
// End Reset _loadingRequest
|
|
||||||
if (self->_drm != nil) {
|
|
||||||
dispatch_queue_t queue = dispatch_queue_create("assetQueue", nil);
|
|
||||||
[asset.resourceLoader setDelegate:self queue:queue];
|
|
||||||
}
|
|
||||||
|
|
||||||
[self playerItemPrepareText:asset assetOptions:assetOptions withCallback:handler];
|
[[PHCachingImageManager new] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
|
||||||
|
handler((AVURLAsset *)asset, assetOptions);
|
||||||
|
}];
|
||||||
|
} else {
|
||||||
|
handler([AVURLAsset URLAssetWithURL:url options:nil], assetOptions);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]] options:nil];
|
||||||
|
handler(asset, assetOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)playerItemForSource:(NSDictionary *)source withCallback:(void(^)(AVPlayerItem *))handler
|
||||||
|
{
|
||||||
|
[self loadAssetFromSource:source withCallback:^(AVURLAsset *asset, NSMutableDictionary *assetOptions) {
|
||||||
|
// Reset _loadingRequest
|
||||||
|
if (self->_loadingRequest != nil) {
|
||||||
|
[self->_loadingRequest finishLoading];
|
||||||
|
}
|
||||||
|
self->_requestingCertificate = NO;
|
||||||
|
self->_requestingCertificateErrored = NO;
|
||||||
|
// End Reset _loadingRequest
|
||||||
|
if (self->_drm != nil) {
|
||||||
|
dispatch_queue_t queue = dispatch_queue_create("assetQueue", nil);
|
||||||
|
[asset.resourceLoader setDelegate:self queue:queue];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self playerItemPrepareText:asset assetOptions:assetOptions withCallback:handler];
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __has_include(<react-native-video/RCTVideoCache.h>)
|
#if __has_include(<react-native-video/RCTVideoCache.h>)
|
||||||
|
Loading…
Reference in New Issue
Block a user