我知道以前已经回答过视频类型问题的持续时间问题,但是我在使用AVAsset
和AVURLAsset
获得一个文件的持续时间方面遇到了真正的困难。我使用以下代码
NSString *itemPathString = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0] stringByAppendingPathComponent:obmodel.actualname];
NSURL *itemPathURL = [NSURL URLWithString:itemPathString];
if([[NSFileManager defaultManager] fileExistsAtPath:itemPathString]){
NSLog(@"File Exists");
}
AVAsset *videoAsset = (AVAsset *)[AVAsset assetWithURL:itemPathURL];
AVAssetTrack *videoAssetTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
NSLog(@"duration: %.2f", CMTimeGetSeconds(videoAssetTrack.timeRange.duration));
if(CMTimeGetSeconds(videoAsset.duration) >= 59.0){
}
但是每次它返回0
时,我也会在headers
之后导入
#import <AVFoundation/AVAsset.h>
#import <CoreMedia/CoreMedia.h>
#import <AVFoundation/AVFoundation.h>
我也尝试过其他一些我知道的代码,但没有一个对我有用。我的视频工作正常,如果我通过iExplorer
播放它,我的道路是好的,但不知道我错过了什么。我想分享一下,我发现我的AVAssets
没有正确加载,请建议我应该做些什么。
发布于 2015-03-25 16:06:49
是的,我以前也有过类似的问题。对我来说,当我用:
NSURL *itemPathURL = [NSURL fileURLWithPath:itemPathString];
而不是
NSURL *itemPathURL = [NSURL URLWithString:itemPathString];
如果你完全确定你的道路是好的,这应该可以解决你的问题。
希望这能有所帮助!
https://stackoverflow.com/questions/29255776
复制