我知道视频类型问题的持续时间之前已得到解答,但我在获取视频持续时间方面遇到了真正的麻烦.mp4
文件通过使用AVAsset
and by 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
未正确加载
请建议我应该做什么。
是的,我以前也遇到过类似的问题。对我来说,当我使用以下方法时,问题就消失了:
NSURL *itemPathURL = [NSURL fileURLWithPath:itemPathString];
代替
NSURL *itemPathURL = [NSURL URLWithString:itemPathString];
如果您完全确定您的路径没问题,这应该可以解决您的问题。
希望这可以帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)