Believe in your own future, will thank yourself right now Sinner Yun

Sinner_Yun

swift 阿里云短视频上传 - VODUploadClient

 1 //视频上传
 2     private func upLoadVideo(videoPath: String){
 3         
 4         let Auth = "eyJTZWN1cml0eVRva2VuIjoiQ0FJUzBBUjFxNkZ0NUIyeWZTaklyNG52TGU3MTJZcEZnN2VJV0g3RHFETm1PY3hxdWZETmlEejJJSDlJZEhWb0FPOGZ2dlUwbTJ0WTdQc1psclV4L1NmdTJrS3ZSaHBrUnZ2WkVwUHR3eklpai9nTFpaRWlhelJteWhlZm81WG1QWEZUUd5akt2aW9TIiwiRXhwaXJhdGlvbiI6IjM2MDAiLCJSZWdpb24iOiJjbi1zaGFuZ2hhaSJ9"
 5         let Address = "eyJFbmRwb2ludCI6Ih0dHBzOi8vb3NzLWNuLXNoYW5naGFpLmFsaXl1bmNzLmNvbSIsIkJ1Y2tldCI6Im91Jzdi8zMmIxYWFkNi0xNmQ0ZTMzZWU0Mi8zMmIxYWFkNi0xNmQ0ZTMzZWU0Mi5tcDQifQ=="
 6         
 7         self.uploader = VODUploadClient.init()
 8         weak var weakSelf = self
 9         let lister: VODUploadListener = VODUploadListener.init()
10         
11         //上传开始:(^OnUploadStartedListener) (UploadFileInfo* fileInfo),fileInfo中存放的是视频信息
12         lister.started = {(info) in
13             XLOG("开始上传")
14             XLOG(info?.filePath)
15             weakSelf?.uploader?.setUploadAuthAndAddress(info, uploadAuth: Auth, uploadAddress: Address)
16         }
17 
18         //上传进度:(UploadFileInfo* fileInfo, long uploadedSize, long totalSize), uploadedSize为上传数据量, totalSize为总文件大小
19         lister.progress = {(info, uploadeSize, totalSize) in
20             XLOG("\(uploadeSize)===== 上传中 =====\(totalSize)")
21         }
22 
23         //上传完成:(UploadFileInfo* fileInfo, VodUploadResult* result), result存放了视频id或者文件(图片)的文件名
24         lister.finish = {(info, result) in
25             XLOG("上完成")
26             XLOG(result)
27             XLOG(result?.videoId)
28         }
29         
30         //上传失败:(UploadFileInfo* fileInfo, NSString *code, NSString * message),code为错误码,messgae为错误信息
31         lister.failure = {(info, code, msg) in
32             XLOG("上传失败")
33             XLOG(msg)
34         }
35         
36         //上传凭证过期:(^OnUploadTokenExpiredListener) ()在这个回调中重新获取上传凭证
37         lister.expire = {() in
38             XLOG("凭证过期了")
39             weakSelf?.uploader?.resume(withAuth: Auth)
40         }
41         
42         //重新获取凭证:(^OnUploadRertyResumeListener) ()这个回调表示重新获取上传凭证成功
43         lister.retryResume = {() in
44             XLOG("要重新获取凭证")
45         }
46         
47         //重新上传:(^OnUploadRertyListener) ()这个回调表示重新开始上传
48         lister.retry = {() in
49             XLOG("要重新上传了")
50         }
51         
52         self.uploader?.setListener(lister)
53         
54         
55         let  vodInfo: VodInfo = VodInfo.init()
56         vodInfo.title       = "laOla-iOS-Test1"
57         vodInfo.desc        = ""
58         vodInfo.cateId      = 0
59         vodInfo.tags        = ""
60         
61         self.uploader?.addFile(videoPath, vodInfo: vodInfo)
62         self.uploader?.start()
63         
64     }



 

posted on 2019-09-20 18:48  Sinner_Yun  阅读(1729)  评论(0编辑  收藏  举报

导航