2015-10-28 82 views
1

我使用requestExportSessionForVideo方法來獲得從PHAsset一個可發送的視頻,但我得到這個警告,並出口會話記錄一個空值:requestExportSessionForVideo零誤差

Null passed to a callee that requires a non-null argument 

下面是方法調用:

[manager requestExportSessionForVideo:asset options:videoOptions exportPreset:AVAssetExportSessionStatusUnknown resultHandler:^(AVAssetExportSession * _Nullable exportSession, NSDictionary * _Nullable info) { 
      NSLog(@"Export session is: %@ ///// Info is %@", exportSession, info); 
     }]; 

所打印的信息看起來再好:

Info is { 
PHImageFileSandboxExtensionTokenKey = "8b504346993c71de48743d3c9c796385d7911ad2;00000000;00000000;000000000000001b;com.apple.avasset.read-only;00000001;01000002;00000000000468eb;/private/var/mobile/Media/DCIM/100APPLE/IMG_0004.MOV"; 
PHImageResultDeliveredImageFormatKey = 20000; 
PHImageResultIsInCloudKey = 0; 
PHImageResultWantedImageFormatKey = 20000; 
} 

如何從PHAsset獲取可發送到雲容器的視頻對象? 此警告是否會影響輸出? 請注意我的資產是使用GMImagePicker選擇的。

回答

3

這可能會幫助您進一步處理。我目前面臨同樣的問題。但下面的方法給了我視頻URL。

PHVideoRequestOptions* options = [[PHVideoRequestOptions alloc] init]; 
    options.version = PHVideoRequestOptionsVersionOriginal; 
    options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic; 
    options.networkAccessAllowed = YES; 
    options.progressHandler = ^(double progress,NSError *error,BOOL* stop, NSDictionary* dict) { 
     NSLog(@"progress %lf",progress); //never gets called 
    }; 


[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset* avasset, AVAudioMix* audioMix, NSDictionary* info){ 
     NSLog(@"##Info:\n%@",info); 
     AVURLAsset* myAsset = (AVURLAsset*)avasset; 
     NSLog(@"##AVAsset URL: %@",myAsset.URL); 
    }]; 


輸出

2015-11-25 12:00:04.482 iLockBox[7602:2587808] ##Info: 
{ 
    PHImageFileSandboxExtensionTokenKey = "7c2094f4c69015b87df6d7c86ec3217cc544e2e2;00000000;00000000;000000000000001b;com.apple.avasset.read-only;00000001;01000002;0000000000ff9a15;/private/var/mobile/Media/DCIM/111APPLE/IMG_1087.MOV"; 
    PHImageResultDeliveredImageFormatKey = 20000; 
    PHImageResultIsInCloudKey = 0; 
    PHImageResultWantedImageFormatKey = 20000; 
} 
2015-11-25 12:00:16.007 iLockBox[7602:2587808] ##AVAsset URL: file:///var/mobile/Media/DCIM/111APPLE/IMG_1087.MOV 



請評論你的結果。

+0

你基本上不能用文件路徑做很多事情,因爲你沒有任何讀取文件的權限。 –

+0

@JohnDing是的,你是對的。 :) – Vats

3

斯威夫特 - 這裏,讓使用requestAVAssetForVideo視頻網址...解決其工作對我來說...

let options = PHVideoRequestOptions() 
options.version = .Original 
options.deliveryMode = .Automatic 
options.networkAccessAllowed = true 

PHCachingImageManager.defaultManager().requestAVAssetForVideo(asset, options: options, resultHandler: 
           { 
            (avAsset, audioMix, info) in 

            dispatch_sync(dispatch_get_main_queue(),{ 
             let theAsset = avAsset as! AVURLAsset 
             let videoURL = theAsset.URL 
             print(videoURL) 

            }) 
          }) 
1

斯威夫特3 @的Pankaj的工作答案的版本,方便

let options = PHVideoRequestOptions() 
options.version = .original 
options.deliveryMode = .automatic 
options.isNetworkAccessAllowed = true 

PHCachingImageManager.default().requestAVAsset(forVideo: phAsset, options: options, resultHandler:{ (avAsset, audioMix, info) in 

     DispatchQueue.main.async { 
      let theAsset = avAsset as! AVURLAsset 
      let videoURL = theAsset.url 
      print(videoURL) 
     } 
})