Explorar o código

发布视频pass

Chris %!s(int64=5) %!d(string=hai) anos
pai
achega
4cecd2a9d7

+ 1 - 1
RainbowPlanet/RainbowPlanet/Macro/RainbowPlanet-Bridging-Header.h

@@ -67,7 +67,7 @@
 
 #import "AliyunPathManager.h"
 #import "QUProgressView.h"
-
+#import "AlivcShortVideoUploadManager.h"
 
 #import "AliyunMagicCameraViewController.h"
 #import "AliyunCropViewController.h"

+ 7 - 0
RainbowPlanet/RainbowPlanet/Modules/PublishModule/AliyunVideo/AlivcShortVideo/ShortVideoFile/Common/Model/AlivcShortVideoUploadManager.h

@@ -65,6 +65,13 @@ typedef NS_ENUM(NSInteger,AlivcUploadStatus){
  */
 @property (nonatomic, weak) id<AlivcShortVideoUploadManagerDelegate> managerDelegate;
 
+//
+@property (nonatomic, strong) NSString *uploadAddress;
+//
+@property (nonatomic, strong) NSString *videoId;
+//
+@property (nonatomic, strong) NSString *uploadAuth;
+
 /**
  设置上传信息
  

+ 6 - 21
RainbowPlanet/RainbowPlanet/Modules/PublishModule/AliyunVideo/AlivcShortVideo/ShortVideoFile/Common/Model/AlivcShortVideoUploadManager.m

@@ -10,7 +10,6 @@
 #import "AliyunMediaConfig.h"
 #import "AliyunPublishService.h"
 #import "AliyunSVideoApi.h"
-//#import "AliVideoClientUser.h"
 #import <sys/utsname.h>
 
 @interface AlivcShortVideoUploadManager () <AliyunIVodUploadCallback>
@@ -21,7 +20,6 @@
 @property(nonatomic, assign) AlivcUploadStatus newStatus; //上传状态
 
 @property(nonatomic, copy) NSString *coverImageUrl;  //封面图的URL
-@property(nonatomic, copy) NSString *videoId; //视频上传成功之后得到视频id
 
 @end
 
@@ -109,7 +107,7 @@ static AliyunVodPublishManager *_uploadManager = nil;
     _newStatus = AlivcUploadStatusUploading;
     if (_managerDelegate &&
         [_managerDelegate respondsToSelector:@selector(uploadManager:
-                                                       uploadStatusChangedTo:)]) {
+                                                         uploadStatusChangedTo:)]) {
         [_managerDelegate uploadManager:self
                   uploadStatusChangedTo:AlivcUploadStatusUploading];
     }
@@ -148,34 +146,21 @@ static AliyunVodPublishManager *_uploadManager = nil;
  上传封面图
  */
 - (void)startUploadImage{
-//    [AliyunSVideoApi getImageUploadAuthWithToken:[AliVideoClientUser shared].token title:@"DefaultTitle" filePath:self.coverImagePath tags:@"DefaultTags" handler:^(NSString * _Nullable uploadAddress, NSString * _Nullable uploadAuth, NSString * _Nullable imageURL, NSString * _Nullable imageId, NSError * _Nullable error) {
-//        if (error) {
-//            NSLog(@"error获取封面凭证:%@", error.description);
-//            [self handleUploadFailed];
-//            return;
-//        }
-//        self.coverImageUrl = imageURL;
-//        [_uploadManager uploadImageWithPath:self.coverImagePath uploadAddress:uploadAddress uploadAuth:uploadAuth];
-//    }];
+    [_uploadManager uploadImageWithPath:self.coverImagePath uploadAddress:self.uploadAddress uploadAuth:self.uploadAuth];
 }
 
 /**
  上传视频
  */
 - (void)startUploadVideo{
-//    [AliyunSVideoApi getVideoUploadAuthWithWithToken:[AliVideoClientUser shared].token title:_videoInfo.title filePath:self.videoPath coverURL:self.coverImageUrl desc:_videoInfo.desc tags:_videoInfo.tags handler:^(NSString * _Nullable uploadAddress, NSString * _Nullable uploadAuth, NSString * _Nullable videoId, NSError * _Nullable error) {
-//        if (error) {
-//            NSLog(@"error:获取视频凭证%@", error.description);
-//            [self handleUploadFailed];
-//            return;
-//        }
-//        self.videoId = videoId;
-//        [_uploadManager uploadVideoWithPath:self.videoPath uploadAddress:uploadAddress uploadAuth:uploadAuth];
-//    }];
+    [_uploadManager uploadVideoWithPath:self.videoPath uploadAddress:self.uploadAddress uploadAuth:self.uploadAuth];
 }
 
 
 - (void)refreshVideo{
+    
+    [_uploadManager refreshWithUploadAuth:self.uploadAuth];
+    
 //    [AliyunSVideoApi refreshVideoUploadAuthWithToken:[AliVideoClientUser shared].token videoId:self.videoId handler:^(NSString * _Nullable uploadAddress, NSString * _Nullable uploadAuth, NSError * _Nullable error) {
 //        if (error) {
 //            NSLog(@"error:%@", error.description);

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/PublishModule/AliyunVideo/AlivcShortVideo/ShortVideoFile/VideoCoverPick/Controller/AliyunCoverPickViewController.h

@@ -11,5 +11,5 @@
 @interface AliyunCoverPickViewController : UIViewController
 @property (nonatomic, assign) CGSize outputSize;
 @property (nonatomic, strong) NSString *videoPath;
-@property (nonatomic, strong) void(^finishHandler)(UIImage *image);
+@property (nonatomic, strong) NSString *taskPath;
 @end

+ 8 - 5
RainbowPlanet/RainbowPlanet/Modules/PublishModule/AliyunVideo/AlivcShortVideo/ShortVideoFile/VideoCoverPick/Controller/AliyunCoverPickViewController.m

@@ -82,15 +82,18 @@
 }
 
 - (void)finishButtonClicked {
-    // FIXME: 完成封面选择,去发布
-    NSLog(@"完成封面选择,去发布");
+    // 完成封面选择,去发布
+    NSString *coverPath = [_taskPath stringByAppendingPathComponent:@"cover.png"];
+    NSData *data = UIImagePNGRepresentation(_coverView.image);
+    [data writeToFile:coverPath atomically:YES];
     
     PublishEditController *pubVc = [[PublishEditController alloc] init];
     pubVc.mediaType = PublishMediaTypeVideo;
+    pubVc.videoPath = _videoPath;
+    pubVc.coverImagePath = coverPath;
+    pubVc.videoSize = _outputSize;
+    pubVc.videoImage = _coverView.image;
     [self.navigationController pushViewController:pubVc animated:YES];
-    
-//    _finishHandler(_coverView.image);
-//    [self.navigationController popViewControllerAnimated:YES];
 }
 
 #pragma mark - pick view delegate

+ 1 - 7
RainbowPlanet/RainbowPlanet/Modules/PublishModule/AliyunVideo/AlivcShortVideo/ShortVideoFile/VideoEdit/Controller/AliyunEditViewController.m

@@ -1264,13 +1264,7 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
     AliyunCoverPickViewController *vc = [AliyunCoverPickViewController new];
     vc.outputSize = _outputSize;
     vc.videoPath = _config.outputPath;
-    vc.finishHandler = ^(UIImage *image) {
-        //        _image = image;
-        //        _coverImageView.image = image;
-        //        _backgroundView.image = image;
-        
-        NSLog(@"----coverImage == %@", image);
-    };
+    vc.taskPath = _taskPath;
     [self.navigationController pushViewController:vc animated:YES];
 }
 

+ 85 - 1
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishEditController/Controller/PublishEditController.swift

@@ -20,6 +20,10 @@ enum PublishMediaType: Int {
 class PublishEditController: BaseViewController {
     
     @objc var mediaType: PublishMediaType = .image
+    @objc var videoPath: String = ""
+    @objc var coverImagePath: String = ""
+    @objc var videoSize: CGSize = CGSize()
+    @objc var videoImage: UIImage = UIImage()
     
     var imgCount: Int = 0
     var majorImageUrl: String?
@@ -38,6 +42,11 @@ class PublishEditController: BaseViewController {
     var pubContent: String = ""
     // 位置
     var location: String = ""
+    // 视频id,当type为video时必填
+    var paraVideo: String = ""
+    
+    var uploadManager: AlivcShortVideoUploadManager?
+    var vUploadFinished: Bool?
     
     // MARK: 控制器生命周期
     override func viewDidLoad() {
@@ -57,6 +66,7 @@ class PublishEditController: BaseViewController {
             uploadAllImages(totalTimes: 0)
         } else {
             subLabel.text = "视频正在上传中(0/1)..."
+            communityVideoUploadAuthApi()
             print("----上传视频")
         }
         
@@ -338,7 +348,7 @@ extension PublishEditController {
         
         print("----mediaType == \(typeStr)\n----pubTitle = \(pubTitle)\n----simuTopicJsonStr == \(simuTopicJsonStr)\n----imgsJsonStr == \(imgsJsonStr)")
         
-        SwiftMoyaNetWorkServiceCommunity.shared().communityPublishApi(type: typeStr, img: majorImageUrl ?? "", topic_ids: simuTopicJsonStr, video: "", title: pubTitle, content: pubContent, location: "", imgs: imgsJsonStr) {
+        SwiftMoyaNetWorkServiceCommunity.shared().communityPublishApi(type: typeStr, img: majorImageUrl ?? "", topic_ids: simuTopicJsonStr, video: paraVideo, title: pubTitle, content: pubContent, location: "", imgs: imgsJsonStr) {
             [weak self] (communityPublishModel) -> (Void) in
             let communityPublishModel = communityPublishModel as? CommunityPublishModel
             print("----发布成功")
@@ -346,3 +356,77 @@ extension PublishEditController {
     }
     
 }
+
+// MARK: - 视频相关处理
+extension PublishEditController: AlivcShortVideoUploadManagerDelegate {
+    
+    // 获取上传地址和凭证
+    func communityVideoUploadAuthApi() {
+        
+        var vTitle: String = ""
+        if videoPath.count > 20 {
+            vTitle = String(videoPath.suffix(20))
+        } else {
+            vTitle = videoPath
+        }
+        SwiftMoyaNetWorkServiceCommunity.shared().communityVideoUploadAuthApi(title: vTitle, filename: vTitle, cover_url: coverImagePath) {
+            [weak self] (communityVideoAuthModel) -> (Void) in
+            let communityVideoAuthModel = communityVideoAuthModel as? CommunityVideoAuthModel
+            self?.paraVideo = communityVideoAuthModel?.videoId ?? ""
+            self?.startUploadVideo(communityVideoAuthModel!)
+        }
+        
+    }
+    
+    // 上传视频
+    func startUploadVideo(_ authModel: CommunityVideoAuthModel) {
+        let info = AliyunUploadSVideoInfo()
+        uploadManager = AlivcShortVideoUploadManager.shared()
+        uploadManager?.setCoverImagePath(coverImagePath, videoInfo: info, videoPath: videoPath)
+        uploadManager?.managerDelegate = self
+        uploadManager?.uploadAddress = authModel.uploadAddress
+        uploadManager?.videoId = authModel.videoId
+        uploadManager?.uploadAuth = authModel.uploadAuth
+        uploadManager?.startUpload()
+    }
+    
+    // 上传进度回调
+    func uploadManager(_ manager: AlivcShortVideoUploadManager!, updateProgress progress: CGFloat) {
+        DispatchQueue.main.async(execute: {
+            self.progressView.progress = Float(progress)
+        })
+    }
+    
+    // 上传状态回调
+    func uploadManager(_ manager: AlivcShortVideoUploadManager!, uploadStatusChangedTo newStatus: AlivcUploadStatus) {
+        switch newStatus {
+        case AlivcUploadStatus.failure:
+            DispatchQueue.main.async(execute: {
+                self.subLabel.text = "上传失败!"
+                SwiftProgressHUD.shared().showText("上传失败!")
+            })
+            
+        case AlivcUploadStatus.success:
+            // 上传封面图
+            self.uploadVideoCoverImage()
+            
+        default:
+            break
+        }
+    }
+    
+    // 上传视频封面图
+    func uploadVideoCoverImage() {
+        SwiftMoyaNetWorkServiceConfig.shared().configUploadSingleImgWithoutHudApi(imageArray: [videoImage]) {
+            [weak self] (imgUrl) -> (Void) in
+            // 设置主图
+            self?.majorImageUrl = imgUrl as? String
+            
+            self?.vUploadFinished = true
+            self?.subLabel.text = "上传成功!"
+            self?.rightButton.isEnabled = true
+            self?.rightButton.backgroundColor = k62CC74Color
+        }
+    }
+    
+}