Objective:
Recently do instant chat items, involving uploading and downloading of videos. Afnetworking uploading images and videos (supports multiple image uploads)
There are some problems in the video download, the video cannot be played after downloading
1 Video Download method
/** * Download file */-(void) Downloadfileurl: (NSString *) Aurl Savepath: (NSString *) Asavepath fileName: (NSString *) afilename tag :(Nsinteger) atag{nsfilemanager *filemanager = [Nsfilemanager Defaultmanager]; Check if the local file already exists nsstring *filename = [NSString stringwithformat:@ "%@/%@", Asavepath, Afilename]; Check if the attachment exists if ([FileManager Fileexistsatpath:filename]) {NSData *audiodata = [NSData datawithcontentsoffile:fil ENAME]; //... Video Download complete operation}else{//create Attachment Store directory if (![ FileManager Fileexistsatpath:asavepath]) {[FileManager Createdirectoryatpath:asavepath WithIntermediateDirecto Ries:yes Attributes:nil Error:nil]; }//Download attachment Nsurl *url = [[Nsurl alloc] initwithstring:aurl]; Nsurlrequest *request = [Nsurlrequest Requestwithurl:url]; Afhttprequestoperation *operation = [[Afhttprequestoperation alloc] initwithrequest:request]; Operation.inputstream = [Nsinputstream Inputstreamwithurl:url]; Operation.outputstream = [Nsoutputstream outputstreamtofileatpath:filename append:no]; Download progress Control/* [Operation setdownloadprogressblock:^ (Nsuinteger bytesread, Long long totalbytesread, long long Totalbytesexpectedtoread) {NSLog (@ "is download:%f", (float) totalbytesread/totalbytesexpectedtoread); }]; *//completed download [Operation setcompletionblockwithsuccess:^ (afhttprequestoperation *operation, id response Object) {NSData *audiodata = [NSData datawithcontentsoffile:filename]; Set the download data to the Res Dictionary object and return the downloaded data with the proxy nsdata//... Video download Complete operation} failure:^ (Afhttprequestoperation *operation, Nserror *error) {//download failed //... Video download failed operation}]; [Operation start]; }}
2 after downloading the video, the file does not have a suffix. MP4 will appear to be unable to play the situation, my solution is, in the above filename plus a suffix. mp4, play is OK.
3 When downloading other files, the film, recording, did not find no suffix on the abnormal display or playback problems, have learned or do im project Welcome to find me to communicate. My software group 156747694
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Problems with iOS video download (Attach afhttprequestoperation download video method)