Problems with iOS video download (Attach afhttprequestoperation download video method)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.