betway必威-betway必威官方网站
做最好的网站

betway必威官方网站:利用AFN上传视频到服务器,

此间介绍用AFN上传本地拍片的录制到服务端。全体思路:获得录制财富,先转为mp5,写进沙盒,然后上传,上传成功后要记得删除沙盒中的文件。

完整思路已经明白,得到录制财富,先转为DVD,写进沙盒,然后上传,上传成功后删除沙盒中的文件。

@Manajay:我的 github 博客

调整和裁减导出摄像

本土拍戏的摄像,上传到服务器:

photoKit框架 丢弃 AssetLibrary

//视频转换为MP4//转码操作..._hud.mode = MBProgressHUDModeIndeterminate;_hud.labelText = @"转码中...";AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:_filePathURL options:nil];NSDateFormatter* formater = [[NSDateFormatter alloc] init];[formater setDateFormat:@"yyyyMMddHHmmss"];_fileName = [NSString stringWithFormat:@"output-%@.mp4",[formater stringFromDate:[NSDate date]]];_outfilePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/%@", _fileName];NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality]) { MyLog(@"outPath = %@",_outfilePath); AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality]; exportSession.outputURL = [NSURL fileURLWithPath:_outfilePath]; exportSession.outputFileType = AVFileTypeMPEG4; [exportSession exportAsynchronouslyWithCompletionHandler:^{ if ([exportSession status] == AVAssetExportSessionStatusCompleted) { MyLog(@"AVAssetExportSessionStatusCompleted---转换成功"); _filePath = _outfilePath; _filePathURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@",_outfilePath]]; MyLog(@"转换完成_filePath = %@\n_filePathURL = %@",_filePath,_filePathURL); //获取大小和长度 [self SetViewText]; [self uploadNetWorkWithParam:@{@"contenttype":@"application/octet-stream",@"discription":description}]; }else{ MyLog(@"转换失败,值为:%li,可能的原因:%@",[exportSession status],[[exportSession error] localizedDescription]); [_hud hide:YES]; [MyHelper showAlertWith:nil txt:@"转换失败,请重试"]; } }];}
//视频转换为MP4
     //转码操作...
     _hud.mode = MBProgressHUDModeIndeterminate;
     _hud.labelText = @"转码中...";
    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:_filePathURL  options:nil];
     NSDateFormatter* formater = [[NSDateFormatter alloc] init];
     [formater setDateFormat:@"yyyyMMddHHmmss"];
    _fileName = [NSString stringWithFormat:@"output-%@.mp4",[formater stringFromDate:[NSDate date]]];
    _outfilePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/%@", _fileName];
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];

    if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality])
    {
        MyLog(@"outPath = %@",_outfilePath);
        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality];
        exportSession.outputURL = [NSURL fileURLWithPath:_outfilePath];
        exportSession.outputFileType = AVFileTypeMPEG4;
        [exportSession exportAsynchronouslyWithCompletionHandler:^{
            if ([exportSession status] == AVAssetExportSessionStatusCompleted) {
                MyLog(@"AVAssetExportSessionStatusCompleted---转换成功");
                _filePath = _outfilePath;
                _filePathURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@",_outfilePath]];
                 MyLog(@"转换完成_filePath = %@n_filePathURL = %@",_filePath,_filePathURL);
                //获取大小和长度
                [self SetViewText];
                [self uploadNetWorkWithParam:@{@"contenttype":@"application/octet-stream",@"discription":description}];
            }else{
                MyLog(@"转换失败,值为:%li,可能的原因:%@",(long)[exportSession status],[[exportSession error] localizedDescription]);
                [_hud hide:YES];
                [MyHelper showAlertWith:nil txt:@"转换失败,请重试"];
            }
        }];

    }






#pragma mark - 开始上传

-(void)uploadNetWorkWithParam:(NSDictionary*)dict
{
     MyLog(@"开始上传_filePath = %@n_filePathURL = %@",_filePath,_filePathURL);
AFHTTPRequestSerializer *ser=[[AFHTTPRequestSerializer alloc]init];
NSMutableURLRequest *request =
[ser multipartFormRequestWithMethod:@"POST"
                          URLString:[NSString stringWithFormat:@"%@%@",kBaseUrl,kVideoUploadUrl]
                         parameters:@{@"path":@"show",@"key":_key,@"discription":dict[@"discription"],@"isimage":@(_isImage)}
          constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                  [formData appendPartWithFileURL:_filePathURL name:@"file" fileName:_fileName mimeType:dict[@"contenttype"] error:nil];
              if (!_isImage) {
   [formData appendPartWithFileURL:_path2Url name:@"tmp" fileName:@"tmp.PNG" mimeType:@"image/png" error:nil];
              }
          } error:nil];
//@"image/png"   @"application/octet-stream"  mimeType
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSProgress *progress = nil;
NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    if (error) {
         MyLog(@"request = %@", request );
         MyLog(@"response = %@", response );
        MyLog(@"Error: %@", error );
        [_hud hide:YES];
        CXAlertView *alert=[[CXAlertView alloc]initWithTitle:NSLocalizedString(@"Warning", nil)
                                                     message:NSLocalizedString(@"Upload Failed",nil)
                                           cancelButtonTitle:NSLocalizedString(@"Iknow", nil)];
        alert.showBlurBackground = NO;
        [alert show];
    } else {
        MyLog(@"%@ %@", response, responseObject);
        NSDictionary *backDict=(NSDictionary *)responseObject;
        if ([backDict[@"success"] boolValue] != NO) {
            _hud.labelText = NSLocalizedString(@"Updating", nil);
            [self UpdateResxDateWithDict:backDict discription:dict[@"discription"]];
            [_hud hide:YES];
        }else{
            [_hud hide:YES];
            [MyHelper showAlertWith:nil txt:backDict[@"msg"]];
        }
    }
    [progress removeObserver:self
                  forKeyPath:@"fractionCompleted"
                     context:NULL];
}];
[progress addObserver:self
           forKeyPath:@"fractionCompleted"
              options:NSKeyValueObservingOptionNew
              context:NULL];
[progress setUserInfoObject:@"someThing" forKey:@"Y.X."];
[uploadTask resume];

}

1. 工作供给

新近在做 录像的分片上传, 使用的框架是 苹果的photoKit.

起来上传

betway必威官方网站, 

2. 疑难

可是付出中开采,使用photoKit不可见收获录像的门路(有个UEscortL路线,不过不能够选择FileManager获得,私有的,只可以官方的图影片仓库可以应用),

本文由betway必威发布于编程开发,转载请注明出处:betway必威官方网站:利用AFN上传视频到服务器,

TAG标签: betway必威
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。