可可:从原始数据(即NSData)创建AVAsset

8
我想使用AVFoundation在OSX上显示视频。我希望能够在运行时从原始数据初始化电影。根据这个文档:https://developer.apple.com/library/mac/#technotes/tn2300/_index.htmlAVAsset是等同于QTKit的QTMovieQTMovie有一个名为movieWithData:error:的函数,可以从数据中加载视频,而我在AVAsset中找不到类似的功能。那么,在AVFoundation中是否可能做到同样的事情呢?
谢谢。
3个回答

2
NSString *tempFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"tmp.mp3"];

NSFileManager *manager = [NSFileManager defaultManager];
[manager createFileAtPath:tempFilePath contents:mp3Data attributes:nil];

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:tempFilePath] options:nil];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [manager removeItemAtPath:tempFilePath error:nil];
        });

1
这并没有回答问题,只是展示了如何将NSData写入临时文件并从中初始化一个AVAsset - Cutterpillow

1
我担心唯一初始化AVAsset实例的可能性是先将数据保存为文件。 AVAsset及其子类仅在构造函数中使用URL。

1

通过实现 AVAssetResourceLoaderDelegate,可以从 NSData 创建一个 AVAsset

具体来说,需要实现:

func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool

必须:

  1. 正确填写loadingRequest.contentInformationRequest。提示,使用loadingRequest.contentInformationRequest.contentType = AVFileType.mycontenttype.rawValue
  2. 正确响应数据

如何做到这一点?我该如何找到你的示例代码?谢谢。 - foolbear

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接