我正在尝试使用新的iOS 8应用扩展程序创建共享扩展程序以分享视频。我想打开照片应用并通过扩展程序分享视频。
我通过以下代码获取视频网址:
NSExtensionItem *inputItem = self.extensionContext.inputItems.firstObject;
NSItemProvider *provider = inputItem.attachments[0];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
if ([provider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeQuickTimeMovie])
{
[provider loadItemForTypeIdentifier:@"com.apple.quicktime-movie" options:nil completionHandler:^(NSURL *path,NSError *error){
if (path)
{
dispatch_async(dispatch_get_main_queue(), ^{
_moviePath = path;
});
}
}];
}
});
但我只收到了视频文件网址:
file:///var/mobile/Media/DCIM/100APPLE/IMG_0062.MOV
我还希望获得更多视频属性,例如:大小和持续时间
我使用了以下代码,但没有工作:
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:_moviePath options:opts];
int second = urlAsset.duration.value / urlAsset.duration.timescale;
和这段代码:
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:_moviePath];
CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"duration: %.2f", seconds);
他们都不工作
和xcode提示:
Error [IRForTarget]: Call to a symbol-only function 'memset' that is not present in the target
error: 0 errors parsing expression
error: The expression could not be prepared to run in the target
您可以帮助我获取视频属性吗?非常感谢!
答案 0 :(得分:0)
现在,以下代码可以正常运行:
NSDictionary *opts = [NSDictionary
dictionaryWithObject:[NSNumber numberWithBool:NO]
forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:_moviePath options:opts];
int second = urlAsset.duration.value / urlAsset.duration.timescale;
我不知道为什么以前不起作用!