2014-09-05 98 views
3

我想創建一個共享擴展以使用新的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 

你可以幫我獲得視頻屬性非常感謝您!

回答

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; 

而且我不知道爲什麼它不工作之前

+1

你有沒有設法找到這個問題的答案!?我正在努力與自己 – YuviGr 2015-09-12 11:18:47

+0

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