1

assets-library://asset/asset.mp4?id=F0D95698-C982-4723-8959-502CE595E3D1&ext=mp4使用ELCImagePickerController. 现在,我必须检索视频名称和媒体 URL,以便使用asiDataFormRequest.

当我使用ImagePickerViewController.Right 选择视频时,视频上传工作正常。现在我必须选择多个视频,所以我正在使用ELCImagePickerController. 但它给出了下面给出的视频网址。 assets-library://asset/asset.mp4?id=F0D95698-C982-4723-8959-502CE595E3D1&ext=mp4

如何将这个 url 转换为 MEdia Url 类型格式。我的主要目标是使用asihttpdatafromrequest并获取这个大小、名称来上传这个视频。

4

1 回答 1

1

@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;
}
于 2014-06-18T15:24:59.380 回答