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 }