如何在tvOS上播放Cloudkit的视频?

时间:2015-10-04 03:16:56

标签: objective-c avplayer cloudkit tvos apple-tv

我有一个问题,我一直试图解决一天,我厌倦了打我的头在墙上。有谁知道怎么做?

1号作品很棒

  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];
    }
    
  2. 不起作用

    - (void) viewDidLoad {
        [super viewDidLoad];
        CKAsset *asset = record[@"VideoFile"];
        AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:asset.fileURL];
        self.player = avPlayer;
        [self.player play];
    }
    
  3. 不起作用

    - (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];
        }
     }
    

0 个答案:

没有答案