|
@@ -27,6 +27,7 @@
|
|
|
#import "MBProgressHUD.h"
|
|
|
#import "NSString+AlivcHelper.h"
|
|
|
#import "UIView+AlivcHelper.h"
|
|
|
+#import "AFNetworking.h"
|
|
|
|
|
|
//公用类相关
|
|
|
#import "AliyunDBHelper.h"
|
|
@@ -57,6 +58,9 @@ typedef enum : NSUInteger {
|
|
|
// TODO:此类需再抽一层,否则会太庞大
|
|
|
@interface AliyunEditViewController () <
|
|
|
AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDelegate>
|
|
|
+{
|
|
|
+ NSURLSessionDownloadTask *_downloadTask;
|
|
|
+}
|
|
|
|
|
|
@property(nonatomic, strong) UIView *movieView;
|
|
|
@property(nonatomic, strong) UIButton *backgroundTouchButton;
|
|
@@ -605,6 +609,7 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive) name:UIApplicationWillResignActiveNotification object:nil];
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resourceDeleteNoti:) name:AliyunEffectResourceDeleteNotification object:nil];
|
|
|
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadMusicAndCombineNoti:) name:@"DownloadMusicAndCombineNoti" object:nil];
|
|
|
|
|
|
}
|
|
|
|
|
@@ -613,6 +618,13 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
|
|
|
}
|
|
|
|
|
|
#pragma mark - Notification Action
|
|
|
+- (void)downloadMusicAndCombineNoti:(NSNotification *)noti {
|
|
|
+ NSString *urlStr = noti.object;
|
|
|
+ NSLog(@"\n------receiveNoti.urlStr == %@", urlStr);
|
|
|
+ [self downloadFileFromServerWithUrlStr:urlStr];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
//资源删除通知
|
|
|
- (void)resourceDeleteNoti:(NSNotification *)noti {
|
|
|
NSArray *deleteResourcePaths = noti.object;
|
|
@@ -651,7 +663,51 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#pragma mark - Common Method
|
|
|
+#pragma mark - Download Music Method
|
|
|
+- (void)downloadFileFromServerWithUrlStr:(NSString *)urlStr{
|
|
|
+
|
|
|
+ NSURL *URL = [NSURL URLWithString:urlStr];
|
|
|
+
|
|
|
+ NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
|
|
+
|
|
|
+ //AFN3.0+基于封住URLSession的句柄
|
|
|
+ AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
|
|
|
+
|
|
|
+ //请求
|
|
|
+ NSURLRequest *request = [NSURLRequest requestWithURL:URL];
|
|
|
+
|
|
|
+ //下载Task操作
|
|
|
+ _downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
|
|
|
+
|
|
|
+ // @property int64_t totalUnitCount; 需要下载文件的总大小
|
|
|
+ // @property int64_t completedUnitCount; 当前已经下载的大小
|
|
|
+
|
|
|
+ // 给Progress添加监听 KVO
|
|
|
+ NSLog(@"%f",1.0 * downloadProgress.completedUnitCount / downloadProgress.totalUnitCount);
|
|
|
+ // 回到主队列刷新UI
|
|
|
+// dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+// self.progressView.progress = 1.0 * downloadProgress.completedUnitCount / downloadProgress.totalUnitCount;
|
|
|
+// });
|
|
|
+
|
|
|
+ } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
|
|
|
+
|
|
|
+ //- block的返回值, 要求返回一个URL, 返回的这个URL就是文件的位置的路径
|
|
|
+
|
|
|
+ NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
|
|
|
+ NSString *path = [cachesPath stringByAppendingPathComponent:response.suggestedFilename];
|
|
|
+ return [NSURL fileURLWithPath:path];
|
|
|
+
|
|
|
+ } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
|
|
|
+ // filePath就是你下载文件的位置,你可以解压,也可以直接拿来使用
|
|
|
+
|
|
|
+ NSString *musicFilePath = [filePath path];// 将NSURL转成NSString
|
|
|
+ NSLog(@"\n------下载音乐成功!path == %@", musicFilePath);
|
|
|
+// /var/mobile/Containers/Data/Application/8E7DC39B-199C-4D88-A2CC-E1E45BEC61AD/Library/Caches/FndRYcJTMSbC1N2UXur3tJSeH_CF_67_60_028.mp3
|
|
|
+ }];
|
|
|
+
|
|
|
+ // 开始执行下载
|
|
|
+ [_downloadTask resume];
|
|
|
+}
|
|
|
|
|
|
#pragma mark - Play Manager
|
|
|
|