我有一个问题我一直试图解决一天,我厌倦了用头撞墙。有人知道怎么做吗?
1 号效果很好
效果很好
- (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]; } }