Objective c 如何在tvOS上播放Cloudkit的视频?
我有一个一天来一直在努力解决的问题,我厌倦了把头撞到墙上。有人知道怎么做吗 1号很好用Objective c 如何在tvOS上播放Cloudkit的视频?,objective-c,avplayer,cloudkit,tvos,apple-tv,Objective C,Avplayer,Cloudkit,Tvos,Apple Tv,我有一个一天来一直在努力解决的问题,我厌倦了把头撞到墙上。有人知道怎么做吗 1号很好用 - (void) viewDidLoad { [super viewDidLoad]; NSURL *url = [NSURL URLWithString:@"http://techslides.com/demos/sample-videos/small.mp4"]; AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:url];
- (void) viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://techslides.com/demos/sample-videos/small.mp4"];
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:url];
self.player = avPlayer;
[self.player play];
}
- (void) viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://techslides.com/demos/sample-videos/small.mp4"];
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:url];
self.player = avPlayer;
[self.player play];
}
- (void) viewDidLoad {
[super viewDidLoad];
CKAsset *asset = record[@"VideoFile"];
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:asset.fileURL];
self.player = avPlayer;
[self.player play];
}
- (void) viewDidLoad {
[super viewDidLoad];
CKAsset *asset = record[@"VideoFile"];
NSString *fileName = record[@"videoFileKey"];
NSData *data = [NSData dataWithContentsOfURL:asset.fileURL];
NSString *cachesDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [cachesDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4", fileName]];
[data writeToFile:path atomically:YES];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSURL *url = [NSURL URLWithString:path];
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:url];
self.player = avPlayer;
[self.player play];
}
}
- (void) viewDidLoad {
[super viewDidLoad];
CKAsset *asset = record[@"VideoFile"];
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:asset.fileURL];
self.player = avPlayer;
[self.player play];
}
- (void) viewDidLoad {
[super viewDidLoad];
CKAsset *asset = record[@"VideoFile"];
NSString *fileName = record[@"videoFileKey"];
NSData *data = [NSData dataWithContentsOfURL:asset.fileURL];
NSString *cachesDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [cachesDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4", fileName]];
[data writeToFile:path atomically:YES];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSURL *url = [NSURL URLWithString:path];
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:url];
self.player = avPlayer;
[self.player play];
}
}
在选项3中,您在哪里设置url?如果像选项1一样使用AVPlayer代码会怎么样?url来自asset.fileURL,文件名来自cloud kit中的记录。如果你检查了应用程序的容器,文件被正确保存,并且可以在quicktime中提取和播放,那么它就不会在缓存目录中的AVPlayer中播放