使用assets-library://asset/asset.mp4?id=F0D95698-C982-4723-8959-502CE595E3D1&ext=mp4
选择视频时,我会收到ELCImagePickerController
个网址。现在,我将使用asiDataFormRequest
检索用于在服务器上上传此视频的视频名称和媒体网址。
当我使用ImagePickerViewController
选择视频时,视频上传工作正常。此时我必须选择多个视频,因此我使用ELCImagePickerController
。但它给出了视频网址,如下所示。
assets-library://asset/asset.mp4?id=F0D95698-C982-4723-8959-502CE595E3D1&ext=mp4
如何以MEdia Url类型格式转换此网址。我的主要目的是使用asihttpdatafromrequest
上传此视频并获取此尺寸,名称。
答案 0 :(得分: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;
}