小編給大家分享一下iOS如何實(shí)現(xiàn)視頻下載并自動(dòng)保存到相冊(cè)功能,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的洪雅網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!iOS視頻下載功能實(shí)現(xiàn),并自動(dòng)保存到相冊(cè)(有MBProgressHUD 可以解開注釋),供大家參考,具體內(nèi)容如下
視頻類定義屬性
///@property (nonatomic,strong) MBProgressHUD *hud; @property (nonatomic,strong) NSURLSession *session; ///視頻播放和下載用的url @property (nonatomic,strong) NSURL *url;
///初始化session - (NSURLSession *)session{ if(_session == nil) { NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; _session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]; } return _session; } ///下載 - (void)download:(UIBarButtonItem *)btnItem{ ///初始化Session _session = [XMConciseVedioPlayer getSession:_session]; ///self.hud = [MBProgressHUD showHUDAddedTo:self animated:YES]; [self downloadFileWithUrl:self.url]; } ///通過url下載 - (void)downloadFileWithUrl:(NSURL *)url{ NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:1.0 timeoutInterval:5.0]; ///下載任務(wù) [[self.session downloadTaskWithRequest:request]resume]; NSURLSessionDownloadTask *task = [_session downloadTaskWithURL:url completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) { ///[self.hud setLabelText:[NSString stringWithFormat:@"下載成功"]]; NSFileManager *fileManger = [NSFileManager defaultManager]; ///沙盒Documents路徑 NSString *documents = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; //拼接文件絕對(duì)路徑 NSString *path = [documents stringByAppendingPathComponent:response.suggestedFilename]; //視頻存放到這個(gè)位置 [fileManger moveItemAtURL:location toURL:[NSURL fileURLWithPath:path] error:nil]; ///保存到相冊(cè) UISaveVideoAtPathToSavedPhotosAlbum(path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil); }]; ///開始下載任務(wù) [task resume]; } //保存視頻完成之后的回調(diào) - (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { if (!error) { ///[self.hud setLabelText:[NSString stringWithFormat:@"保存到相冊(cè)成功"]]; } else { ///[self.hud setLabelText:[NSString stringWithFormat:@"下載失敗"]]; } ///[self.hud hide:YES afterDelay:3.0]; } // 進(jìn)度數(shù)據(jù) - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite{ float progress = (float)totalBytesWritten / totalBytesExpectedToWrite; long pro = (long)(progress *100); ///[self.hud setLabelText:[NSString stringWithFormat:@"下載進(jìn)度:%ld%%",pro]]; }
看完了這篇文章,相信你對(duì)“iOS如何實(shí)現(xiàn)視頻下載并自動(dòng)保存到相冊(cè)功能”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝各位的閱讀!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站vcdvsql.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
文章標(biāo)題:iOS如何實(shí)現(xiàn)視頻下載并自動(dòng)保存到相冊(cè)功能-創(chuàng)新互聯(lián)
URL分享:http://vcdvsql.cn/article8/ddjeop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、App開發(fā)、云服務(wù)器、手機(jī)網(wǎng)站建設(shè)、微信公眾號(hào)、動(dòng)態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容