2 sinat 36121901 sinat_36121901 于 2016.09.12 17:17 提问

从assert中获得视频 转换成data 写入文件 写入成功,但是视频播放不了啊

贴点我的转换代码

  • (void)videoWithUrl:(NSURL *)url withFilePath:(NSString *)filePath
    {

    [[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
    NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:filePath];
    static const NSUInteger BufferSize = 1024*1024;

    ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    if (url) {

        [assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) {
    
            ALAssetRepresentation *rep=[asset defaultRepresentation];
    
            uint8_t *buffer = calloc(BufferSize, sizeof(*buffer));
            NSUInteger offset = 0, bytesRead = 0;
    
            do {
    
                    bytesRead = [rep getBytes:buffer fromOffset:offset length:BufferSize error:nil];
                    [handle writeData:[NSData dataWithBytesNoCopy:buffer length:bytesRead freeWhenDone:NO]];
                    offset += bytesRead;
    
            } while (bytesRead > 0);
    
            free(buffer);
    

1个回答

dabocaiqq
dabocaiqq   2016.11.16 01:45
Csdn user default icon
上传中...
上传图片
插入图片