从 ALAsset URL 创建时,AVAsset 没有曲目或持续时间
我正在从 ALAssetsLibrary 中提取所有视频资源(基本上是从本机相机应用程序记录的所有内容)。然后,我对每个视频资产运行一个枚举,对每个视频执行此操作:
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
//Get the URL location of the video
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSURL *url = [representation url];
//Create an AVAsset from the given URL
NSDictionary *asset_options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVAsset *avAsset = [[AVURLAsset alloc] initWithURL:url options:asset_options];//[AVURLAsset URLAssetWithURL:url options:asset_options];
//Here is the problem
NSLog([NSString stringWithFormat:@"%i", [avAsset.tracks count]]);
NSLog([NSString stringWithFormat:@"%f", CMTimeGetSeconds(avAsset.duration)]);
}
NSLog 报告我从 ALAsset 获得的 AVAsset 有 0 个轨道,持续时间为 0.0 秒。我检查了网址,它是“assets-library://asset/asset.MOV?id=9F482CF8-B4F6-40C2-A687-0D05F5F25529&ext=MOV”,这似乎是正确的。我知道 alAsset 实际上是一个视频,而且是正确的视频,因为我已经显示了 alAsset.thumbnail,并且它显示了视频的正确缩略图。
所有这些让我相信 avAsset 的初始化出了问题,但对于我的一生,我无法弄清楚出了什么问题。谁能帮助我吗?
更新:
我想我已经确认 ALAssetRepresentation 提供给我的网址有错误,这很奇怪,因为它给了我正确的缩略图。我在以下位置添加了这段代码:
NSLog([NSString stringWithFormat:@"%i", [url checkResourceIsReachableAndReturnError:&error]]);
NSLog([NSString stringWithFormat:@"%@", error]);
它给了我这样的信息:
0
Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x19df60 {}
我仍然不确定是什么导致了这种情况。我唯一注意到的是网址“assets-library://asset/asset.MOV?id=9F482CF8-B4F6-40C2-A687-0D05F5F25529&ext=MOV”与我所看到的不同因为我一直在寻找这个。我在其他地方看到的看起来更像是“assets-library://asset/asset.MOV?id=1000000394&ext=MOV”,带有数字而不是字母数字、破折号分隔的名称。
如果有帮助的话,我正在使用 XCode 4.2 Beta 和 iOS5。如果您能想到什么,请告诉我。谢谢。
I'm pulling all of the video assets from ALAssetsLibrary (Basically everything that's being recorded from the native camera app). I am then running an enumeration on each video asset that does this to each video:
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
//Get the URL location of the video
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSURL *url = [representation url];
//Create an AVAsset from the given URL
NSDictionary *asset_options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVAsset *avAsset = [[AVURLAsset alloc] initWithURL:url options:asset_options];//[AVURLAsset URLAssetWithURL:url options:asset_options];
//Here is the problem
NSLog([NSString stringWithFormat:@"%i", [avAsset.tracks count]]);
NSLog([NSString stringWithFormat:@"%f", CMTimeGetSeconds(avAsset.duration)]);
}
NSLog is reporting that the AVAsset that I've gotten from my ALAsset has 0 tracks, and has a duration of 0.0 seconds. I checked the url, and it's "assets-library://asset/asset.MOV?id=9F482CF8-B4F6-40C2-A687-0D05F5F25529&ext=MOV" which seems correct. I know alAsset is actually a video, and the correct video, because I've displayed alAsset.thumbnail, and it's shown the correct thumbnail for the video.
All this leads me to believe there's something going wrong in the initialization for avAsset, but for the life of me, I can't figure out what's going wrong. Can anyone help me?
Update:
I think i've confirmed that the url being given to me by ALAssetRepresentation is faulty, which is weird because it gives me the correct thumbnail. I added this code in:
NSLog([NSString stringWithFormat:@"%i", [url checkResourceIsReachableAndReturnError:&error]]);
NSLog([NSString stringWithFormat:@"%@", error]);
It gives me this:
0
Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x19df60 {}
I'm still not sure what would cause that. The only thing I'm noticing is the url, which is "assets-library://asset/asset.MOV?id=9F482CF8-B4F6-40C2-A687-0D05F5F25529&ext=MOV" is different from what I've seen as I've been searching around for this. The one i've seen elsewhere looks more like "assets-library://asset/asset.MOV?id=1000000394&ext=MOV", with a number instead of an alphanumeric, dash separated name.
If it helps, I'm using XCode 4.2 Beta, and iOS5. Please let me know if you can think of anything. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,看起来这是 iOS5 beta v1 中的一个错误。我升级到最新的并且有效。感谢那些看过我的问题的人。
Okay, looks like it was a bug in the iOS5 beta v1. I upgraded to the newest and it worked. Thanks to those who took a look at my question.