Browse Source

1.歌单保存管理

huangxiaodong 1 year ago
parent
commit
54c8dd1ccf

+ 12 - 0
创维盒子/双子星云手机.xcodeproj/project.pbxproj

@@ -1174,6 +1174,10 @@
 		6BF558BA2C4508CB00701854 /* previewAudioPortraitDetailsView.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BF558B72C4508CB00701854 /* previewAudioPortraitDetailsView.h */; };
 		6BF558BB2C4508CB00701854 /* previewAudioPortraitDetailsView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BF558B82C4508CB00701854 /* previewAudioPortraitDetailsView.m */; };
 		6BF558BC2C4508CB00701854 /* previewAudioPortraitDetailsView.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BF558B72C4508CB00701854 /* previewAudioPortraitDetailsView.h */; };
+		6BF558BF2C4515B500701854 /* audioPlayListManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BF558BE2C4515B500701854 /* audioPlayListManager.m */; };
+		6BF558C02C4515B500701854 /* audioPlayListManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BF558BD2C4515B500701854 /* audioPlayListManager.h */; };
+		6BF558C12C4515B500701854 /* audioPlayListManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BF558BE2C4515B500701854 /* audioPlayListManager.m */; };
+		6BF558C22C4515B500701854 /* audioPlayListManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BF558BD2C4515B500701854 /* audioPlayListManager.h */; };
 		6BFF26882AF8949F00FCB4F7 /* playerShowSecretkeyView.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BFF26862AF8949F00FCB4F7 /* playerShowSecretkeyView.h */; };
 		6BFF26892AF8949F00FCB4F7 /* playerShowSecretkeyView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BFF26872AF8949F00FCB4F7 /* playerShowSecretkeyView.m */; };
 		6BFF268C2AF8E1C600FCB4F7 /* forgetPwdViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BFF268A2AF8E1C600FCB4F7 /* forgetPwdViewController.h */; };
@@ -1904,6 +1908,8 @@
 		6BF558B22C44F11C00701854 /* previewAudioPortraitTopMoreView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = previewAudioPortraitTopMoreView.m; sourceTree = "<group>"; };
 		6BF558B72C4508CB00701854 /* previewAudioPortraitDetailsView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = previewAudioPortraitDetailsView.h; sourceTree = "<group>"; };
 		6BF558B82C4508CB00701854 /* previewAudioPortraitDetailsView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = previewAudioPortraitDetailsView.m; sourceTree = "<group>"; };
+		6BF558BD2C4515B500701854 /* audioPlayListManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = audioPlayListManager.h; sourceTree = "<group>"; };
+		6BF558BE2C4515B500701854 /* audioPlayListManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = audioPlayListManager.m; sourceTree = "<group>"; };
 		6BFF26862AF8949F00FCB4F7 /* playerShowSecretkeyView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = playerShowSecretkeyView.h; sourceTree = "<group>"; };
 		6BFF26872AF8949F00FCB4F7 /* playerShowSecretkeyView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = playerShowSecretkeyView.m; sourceTree = "<group>"; };
 		6BFF268A2AF8E1C600FCB4F7 /* forgetPwdViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = forgetPwdViewController.h; sourceTree = "<group>"; };
@@ -3128,6 +3134,8 @@
 				6B5D867E2C22EA5B008D25EA /* lastFileManager.m */,
 				6B8A5ADE2C3BCC0E00E40B19 /* lastFileModel.h */,
 				6B8A5ADF2C3BCC0E00E40B19 /* lastFileModel.m */,
+				6BF558BD2C4515B500701854 /* audioPlayListManager.h */,
+				6BF558BE2C4515B500701854 /* audioPlayListManager.m */,
 			);
 			path = recenFile;
 			sourceTree = "<group>";
@@ -3767,6 +3775,7 @@
 				6B2C1E4E2C070ADE00FDCF82 /* ZFUtilities.h in Headers */,
 				6B8661D72BBA53B600B19846 /* noticeModel.h in Headers */,
 				6B2C1E462C070ADE00FDCF82 /* ZFSmallFloatControlView.h in Headers */,
+				6BF558C02C4515B500701854 /* audioPlayListManager.h in Headers */,
 				6B2C1E1C2C070ADE00FDCF82 /* ZFAVPlayerManager.h in Headers */,
 				6B8FF6C12B05B24D00800981 /* uploadFileRecordCell.h in Headers */,
 				6B45C5082B5FA2DD007E6911 /* diskListTableCell.h in Headers */,
@@ -4020,6 +4029,7 @@
 				6B2C1E4F2C070ADE00FDCF82 /* ZFUtilities.h in Headers */,
 				6B8661D82BBA53B600B19846 /* noticeModel.h in Headers */,
 				6B2C1E472C070ADE00FDCF82 /* ZFSmallFloatControlView.h in Headers */,
+				6BF558C22C4515B500701854 /* audioPlayListManager.h in Headers */,
 				6B2C1E1D2C070ADE00FDCF82 /* ZFAVPlayerManager.h in Headers */,
 				6BD506E22B9576A4006E7CB0 /* uploadFileRecordCell.h in Headers */,
 				6BD506E32B9576A4006E7CB0 /* diskListTableCell.h in Headers */,
@@ -4755,6 +4765,7 @@
 				6B07AC272BF85859005C2B0E /* ShareRecordModel.m in Sources */,
 				6B2C1E2B2C070ADE00FDCF82 /* ZFLandScapeControlView.m in Sources */,
 				6BD507A62B9576A4006E7CB0 /* HWBookmarkModel.m in Sources */,
+				6BF558C12C4515B500701854 /* audioPlayListManager.m in Sources */,
 				6BD507A72B9576A4006E7CB0 /* NSCache+BGCache.m in Sources */,
 				6BD507A82B9576A4006E7CB0 /* uploadFileRecordBgScorllView.m in Sources */,
 				6BD507A92B9576A4006E7CB0 /* AboutViewController.m in Sources */,
@@ -5090,6 +5101,7 @@
 				6B07AC262BF85859005C2B0E /* ShareRecordModel.m in Sources */,
 				6B2C1E2A2C070ADE00FDCF82 /* ZFLandScapeControlView.m in Sources */,
 				A00221E727EB25B000E45F78 /* HWBookmarkModel.m in Sources */,
+				6BF558BF2C4515B500701854 /* audioPlayListManager.m in Sources */,
 				A08A94FC27E9A4E400C544BB /* NSCache+BGCache.m in Sources */,
 				6B72725C2B0E22D000C03F87 /* uploadFileRecordBgScorllView.m in Sources */,
 				184C8AD62A949D5900F26650 /* AboutViewController.m in Sources */,

+ 3 - 0
创维盒子/双子星云手机/AppDelegate/SceneDelegate.m

@@ -39,6 +39,7 @@
 #import "mineViewController.h"
 #import "lastFileManager.h"
 #import "customDownloadManager.h"
+#import "audioPlayListManager.h"
 
 @interface SceneDelegate ()<SetUsePWDViewControllerDelegate,GuideViewControllerDelegate,UITabBarControllerDelegate>
 @property(nonatomic, strong)   CalculatorViewController *calculatorVC;
@@ -285,6 +286,7 @@
     [boxDownloadFileManager shareInstance];
     
     [lastFileManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
+    [audioPlayListManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
     
     //获取NAS相关信息
     [self getNASMsgFun];
@@ -920,6 +922,7 @@
     [customDownloadManager shareManager].uid = uid;
     
     [lastFileManager shareManager].uid = uid;
+    [audioPlayListManager shareManager].uid = uid;
 }
 
 #pragma mark 上报版本号信息

+ 4 - 1
创维盒子/双子星云手机/Class/Set/previewFile/audioPlayerViewController.m

@@ -11,6 +11,7 @@
 
 #import "NASFileAudioModel.h"
 #import "lastFileManager.h"
+#import "audioPlayListManager.h"
 #import <QuartzCore/QuartzCore.h>
 
 #import "previewAudioPortraitTopMoreView.h"
@@ -471,6 +472,7 @@
 {
     //1.删除最近文件数据
     [[lastFileManager shareManager] deleteFileInfoWithUrl:path];
+    [[audioPlayListManager shareManager] deleteFileInfoWithUrl:path];
     
     if(_didNeedToRegetDataFun){
         _didNeedToRegetDataFun();
@@ -636,7 +638,7 @@
     }else{
         HLog(@"状态码:%lu",(unsigned long)statusCode);
         [[iToast makeText:NSLocalizedString(@"play_video_fail_tip",nil)] show];
-        [[DFPlayer sharedPlayer] df_pause];
+        [[DFPlayer sharedPlayer] df_next];
     }
 }
 
@@ -696,6 +698,7 @@
         lastFileMod.lastPreTime = [iTools getNowTimeStamp];
         
         [[lastFileManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path];
+        [[audioPlayListManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path];
         
     }
 }

+ 31 - 0
创维盒子/双子星云手机/NAS/recenFile/audioPlayListManager.h

@@ -0,0 +1,31 @@
+//
+//  audioPlayListManager.h
+//  双子星云手机
+//
+//  Created by xd h on 2024/7/15.
+//
+
+#import <Foundation/Foundation.h>
+#import "lastFileModel.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+#define KaudioPlayListDirector  @"audioPlayList"
+#define KaudioPlayListkey  @"audioPlayListKey"
+
+@interface audioPlayListManager : NSObject
+@property(nonatomic,strong) NSString *uid;//用户id 用来创建文件夹路径 防止不要用户的缓存关联
+@property (nonatomic, strong) NSMutableDictionary * _Nullable audioPlayPList;
+@property (nonatomic, strong) NSMutableArray * _Nullable audioPlayListArr;
+
+
+/** 实例化对象(单例) */
++ (instancetype)shareManager;
+
+/**  增加配置信息 */
+- (BOOL)saveFileInfoWith:(lastFileModel *)lastFileMod with:(NSString*)fullPath;
+/**  删除配置信息 */
+- (BOOL)deleteFileInfoWithUrl:(NSString *)fullPath;
+@end
+
+NS_ASSUME_NONNULL_END

+ 182 - 0
创维盒子/双子星云手机/NAS/recenFile/audioPlayListManager.m

@@ -0,0 +1,182 @@
+//
+//  audioPlayListManager.m
+//  双子星云手机
+//
+//  Created by xd h on 2024/7/15.
+//
+
+#import "audioPlayListManager.h"
+#import <MJExtension.h>
+
+@implementation audioPlayListManager
+
++ (instancetype)shareManager {
+    static audioPlayListManager *_instance;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        _instance = [[self alloc] init];
+    });
+    return _instance;
+}
+
+- (instancetype)init {
+
+    if (self = [super init]) {
+    }
+    return self;
+}
+
+- (NSString*)uid{
+    if(!_uid || _uid.length == 0){
+        return @"userName";
+    }
+    
+    return _uid;
+}
+
+- (NSString *)getFullDirector {
+
+    NSString *account = self.uid;
+    if (account.length != 0)
+    {
+         NSString *fileFolder = [HWDataManager documentPathForAccount:account fileFolder:KaudioPlayListDirector];
+        // 创建文件储存路径
+        if (![[NSFileManager defaultManager] fileExistsAtPath:fileFolder]) {
+            [[NSFileManager defaultManager] createDirectoryAtPath:fileFolder withIntermediateDirectories:YES attributes:nil error:nil];
+        }
+         return fileFolder;
+     }else {
+         HLog(@"创建文件失败!");
+         return @"";
+     }
+}
+
+#pragma mark- last file plist Path
+- (NSString *)getAudioPlayListPlistPath {
+    NSString *fileFolder = [self getFullDirector];
+    return [fileFolder stringByAppendingPathComponent:@"audioPlayList.plist"];;
+}
+
+#pragma mark- last file  plist
+- (NSMutableDictionary *)audioPlayPList {
+    
+    if (!_audioPlayPList) { // 内存没有
+        _audioPlayPList = [[NSDictionary dictionaryWithContentsOfFile:[self getAudioPlayListPlistPath]] mutableCopy]; // 本地加载
+        if (!_audioPlayPList) { // 本地没有,分配内存
+            _audioPlayPList = [NSMutableDictionary dictionary];
+        }
+    }
+    return _audioPlayPList;
+}
+
+
+- (NSMutableArray*)audioPlayListArr{
+    if (!_audioPlayListArr) { // 内存没有
+        NSMutableArray *dataArr = [NSMutableArray new];
+        
+        if (self.audioPlayPList) {
+            if([[self.audioPlayPList allKeys] containsObject:KaudioPlayListkey]){
+                NSArray *lastDataArr = self.audioPlayPList[KaudioPlayListkey];
+                
+                for (int i=0; i<lastDataArr.count; i++) {
+                    NSDictionary *dict = lastDataArr[i];
+                    lastFileModel *model = [lastFileModel mj_objectWithKeyValues:dict];
+                    if(model){
+                        [dataArr addObject:model];
+                    }
+                }
+            }
+            
+        }
+        
+        _audioPlayListArr = dataArr;
+        
+    }
+    return _audioPlayListArr;
+}
+
+/**  增加配置信息 */
+- (BOOL)saveFileInfoWith:(lastFileModel *)lastFileMod with:(NSString*)fullPath {
+    
+    if(!lastFileMod || !fullPath){
+        return NO;
+    }
+    
+    BOOL flag = NO;
+    @synchronized (self) {
+        NSString *key = fullPath;
+        //1.本地持久化
+        NSMutableDictionary *dictM =  self.audioPlayPList;
+        NSMutableArray *dataArr = self.audioPlayListArr;
+        
+        
+        BOOL isInPlayList = NO;
+        
+        NSMutableArray *saveDictArr = [NSMutableArray new];
+        for (lastFileModel*model in dataArr) {
+            if([model.path isEqualToString:fullPath]){
+                isInPlayList = YES;
+                break;
+            }
+            
+            NSDictionary *dict = [model lastFileInfoFun];
+            [saveDictArr addObject:dict];
+        }
+        
+        if(isInPlayList){
+            HLog(@"音乐保存在播放列表里面了")
+            return YES;
+        }
+        
+        //1.写到内存
+        [dataArr addObject:lastFileMod];
+        
+        //2.本地持久化
+        NSDictionary *dict = [lastFileMod lastFileInfoFun];
+        [saveDictArr addObject:dict];
+        
+        if(saveDictArr){
+            [dictM setValue:saveDictArr forKey:KaudioPlayListkey];
+        }
+        
+        NSString * PlistPath = [self getAudioPlayListPlistPath];
+        flag = [dictM writeToFile:PlistPath atomically:YES];
+    }
+    
+    return flag;
+    
+}
+
+/**  删除配置信息 */
+- (BOOL)deleteFileInfoWithUrl:(NSString *)fullPath {
+    if(!fullPath){
+        return NO;
+    }
+    
+    BOOL flag = NO;
+    @synchronized (self) {
+        
+        //1.内存删除
+        for (lastFileModel*preModel in self.audioPlayListArr) {
+            if([preModel.path isEqualToString:fullPath]){
+                [self.audioPlayListArr removeObject:preModel];
+                break;
+            }
+        }
+        
+        //2.本地持久化删除
+        NSMutableArray *saveDictArr = [NSMutableArray new];
+        for (lastFileModel*model in self.audioPlayListArr) {
+            
+            NSDictionary *dict = [model lastFileInfoFun];
+            [saveDictArr addObject:dict];
+        }
+        
+        [self.audioPlayPList setValue:saveDictArr forKey:KaudioPlayListkey];
+        flag = [self.audioPlayPList writeToFile:[self getAudioPlayListPlistPath] atomically:YES];
+        
+    }
+    return flag;
+}
+
+@end