繁体   English   中英

如何在iOS8共享扩展中获取视频属性

[英]How to get video attributes in iOS8 share extension

我正在尝试使用新的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

你可以帮我获取视频属性吗?非常感谢你!

现在以下代码可以正常工作:

NSDictionary *opts = [NSDictionary 
    dictionaryWithObject:[NSNumber numberWithBool:NO]
    forKey:AVURLAssetPreferPreciseDurationAndTimingKey];

AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:_moviePath options:opts];  
int second = urlAsset.duration.value / urlAsset.duration.timescale; 

我不知道为什么它以前不起作用!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM