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

问题描述:

我想创建一个共享扩展以使用新的iOS 8应用程序扩展共享视频。我想要打开照片应用程序并通过我的扩展程序共享视频。如何在iOS8共享扩展中获取视频属性

我通过以下代码获得视频网址:

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; 

而且我不知道为什么它不工作之前

+1

你有没有设法找到这个问题的答案!?我正在努力与自己 – YuviGr 2015-09-12 11:18:47

+0

你有结果? – 2015-10-16 06:35:03