2014-02-21 39 views
1

當使用ELCImagePickerController選擇視頻時,我得到的網址是assets-library://asset/asset.mp4?id=F0D95698-C982-4723-8959-502CE595E3D1&ext=mp4。現在,我必須使用asiDataFormRequest檢索視頻名稱和媒體網址,以便在服務器上上傳視頻。如何從ALAsset Url獲取視頻網址以在服務器上播放視頻?

視頻上傳工作正常,當我用ImagePickerViewController選擇視頻。現在我必須選擇多個視頻,所以我使用ELCImagePickerController。但它提供了視頻網址,如下所示。 assets-library://asset/asset.mp4?id=F0D95698-C982-4723-8959-502CE595E3D1&ext=mp4

如何將此網址轉換爲MEdia Url類型格式。我的主要目的是使用asihttpdatafromrequest上傳此視頻並獲取此大小名稱。

請幫幫我。謝謝

回答

0

@KDRocks。此代碼正在成功運行以獲取具有完整路徑的名稱。

-(NSString*) videoAssetURLToTempFile:(NSURL*)url 
{ 
    NSString * surl = [url absoluteString]; 
    NSString * ext = [surl substringFromIndex:[surl rangeOfString:@"ext="].location + 4]; 
    NSTimeInterval ti = [[NSDate date]timeIntervalSinceReferenceDate]; 
    NSString * filename = [NSString stringWithFormat: @"%f.%@",ti,ext]; 
    NSString * tmpfile = [NSTemporaryDirectory() stringByAppendingPathComponent:filename]; 

    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) 
    { 
     ALAssetRepresentation * rep = [myasset defaultRepresentation]; 
     NSUInteger size = [rep size]; 
     const int bufferSize = 8192; 
     NSLog(@"Writing to %@",tmpfile); 
     FILE* f = fopen([tmpfile cStringUsingEncoding:1], "wb+"); 
     if (f == NULL) 
     { 
      NSLog(@"Can not create tmp file."); 
      return; 
     } 
     Byte * buffer = (Byte*)malloc(bufferSize); 
     int read = 0, offset = 0, written = 0; 
     NSError* err; 
     if (size != 0) { 
     do { 
      read = [rep getBytes:buffer 
         fromOffset:offset 
          length:bufferSize 
          error:&err]; 
      written = fwrite(buffer, sizeof(char), read, f); 
      offset += read; 
     } while (read != 0); 
     } 
     fclose(f); 
    }; 
    ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) 
    { 
     NSLog(@"Can not get asset - %@",[myerror localizedDescription]); 

    }; 
    if(url) 
    { 
     ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init]; 
     [assetslibrary assetForURL:url 
        resultBlock:resultblock 
        failureBlock:failureblock]; 
    } 
    return tmpfile; 
}