[英]How to get video attributes in iOS8 share extension
I am trying to create a sharing extension to share videos using the new iOS 8 app extensions.I want to open the photo app and share the video by my extension. 我正在尝试使用新的iOS 8应用扩展程序创建共享扩展程序以分享视频。我想打开照片应用并通过我的扩展程序分享视频。
I get the video url by following codes: 我通过以下代码获取视频网址:
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;
});
}
}];
}
});
But I only got the video file url: 但我只得到了视频文件网址:
file:///var/mobile/Media/DCIM/100APPLE/IMG_0062.MOV
I also want to get more video attributes ,like: size and duration 我还希望获得更多视频属性,例如:大小和持续时间
I used following codes,but not work: 我使用了以下代码,但没有工作:
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:_moviePath options:opts];
int second = urlAsset.duration.value / urlAsset.duration.timescale;
and this code: 而这段代码:
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:_moviePath];
CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"duration: %.2f", seconds);
they are all do not work 他们都不行
and xcode tips: 和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
You can help me to get the video attributes?Thank you very much! 你可以帮我获取视频属性吗?非常感谢你!
Now the following codes do working: 现在以下代码可以正常工作:
NSDictionary *opts = [NSDictionary
dictionaryWithObject:[NSNumber numberWithBool:NO]
forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:_moviePath options:opts];
int second = urlAsset.duration.value / urlAsset.duration.timescale;
And I don't know Why it does not work before! 我不知道为什么它以前不起作用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.