Selaa lähdekoodia

1.录音功能--进行中

huangxiaodong 2 kuukautta sitten
vanhempi
commit
4562b11b6a

+ 22 - 10
创维盒子/code/mine/recordViewController.m

@@ -214,8 +214,9 @@
         HLog(@"Error reading contents of directory: %@", error.localizedDescription);
     }
     
-    [_audioArr removeAllObjects];
-    BOOL isFirstType = YES;
+    NSMutableArray *dataArr = [NSMutableArray new];
+    
+    //BOOL isFirstType = YES;
     
     for (NSString *fileName in fileList) {
         NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];
@@ -244,14 +245,15 @@
         NSURL *fileUrl = [NSURL URLWithString:model.filePath];
         NSTimeInterval time  = [self getDurationOfAudioFile:fileUrl];
         model.totalTime =  (NSInteger)ceil(time);  // 结果为 5;
+        model.showAllType  = NO;
         
-        if (isFirstType) {
-            model.showAllType  = YES;
-            isFirstType = NO;
-        }
-        else{
-            model.showAllType  = NO;
-        }
+//        if (isFirstType) {
+//            model.showAllType  = YES;
+//            isFirstType = NO;
+//        }
+//        else{
+//            model.showAllType  = NO;
+//        }
         
         // 创建文件信息字典
 //        NSDictionary *fileInfo = @{
@@ -262,9 +264,19 @@
 //            @"modificationDate": fileAttributes[NSFileModificationDate] ?: [NSDate date]
 //        };
         
-        [_audioArr addObject:model];
+        [dataArr addObject:model];
     }
     
+    // 假设你的对象有一个名为 dateProperty 的 NSDate 属性
+    NSArray *sortedArray = [dataArr sortedArrayUsingComparator:^NSComparisonResult(recordFileModel* obj1, recordFileModel* obj2) {
+        return [obj2.modificationDate compare:obj1.modificationDate];
+    }];
+    
+    [_audioArr removeAllObjects];
+    [_audioArr addObjectsFromArray:sortedArray];
+    
+    recordFileModel *firstModel = _audioArr.firstObject;
+    firstModel.showAllType  = YES;
 }
 
 #pragma mark 获取录音文件的时长

+ 44 - 1
创维盒子/code/mine/view/recordingView.m

@@ -7,6 +7,12 @@
 
 #import "recordingView.h"
 #import "AudioRecorderManager.h"
+@interface recordingView ()
+@property(nonatomic,strong)UILabel * titlelabel;
+@property(nonatomic,strong)UILabel * timerlabel;
+@property(nonatomic,assign)NSInteger second;
+@property(nonatomic,strong)NSTimer * secondTimer;
+@end
 
 @implementation recordingView
 
@@ -67,13 +73,50 @@
     }];
     
     
+    //标题
+    _titlelabel = [[UILabel alloc] init];
+    [whiteBgView addSubview:_titlelabel];
+    _titlelabel.font = [UIFont systemFontOfSize:14.f];
+    _titlelabel.textAlignment = NSTextAlignmentCenter;
+    [_titlelabel setTextColor:HW0A132BColor];
+    [_titlelabel mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.left.mas_equalTo(12.0);
+        make.top.mas_equalTo(15.0);
+        make.height.mas_equalTo(20.0);
+        make.right.mas_equalTo(-12.f);
+    }];
+    
+    _timerlabel = [[UILabel alloc] init];
+    [whiteBgView addSubview:_timerlabel];
+    _timerlabel.font = [UIFont systemFontOfSize:12.f];
+    _timerlabel.text = @"00:00:00";
+    _timerlabel.textAlignment = NSTextAlignmentCenter;
+    [_timerlabel setTextColor:[UIColor hwColor:@"979797"]];
+    [_timerlabel mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.left.mas_equalTo(12.0);
+        make.top.mas_equalTo(15.0);
+        make.height.mas_equalTo(20.0);
+        make.right.mas_equalTo(-12.f);
+    }];
+    
 }
 
 #pragma mark 开始录音
 - (void)beginRecordFunWith:(NSInteger)curIndex;
 {
-    [AudioRecorderManager sharedManager].curRecordName = [[NSString alloc] initWithFormat:@"record%ld.m4a",curIndex];
+    NSString *curName = [[NSString alloc] initWithFormat:@"record%ld.m4a",curIndex];
+    _titlelabel.text = curName;
+    [AudioRecorderManager sharedManager].curRecordName = curName;
     [[AudioRecorderManager sharedManager] startRecording];
+    
+    //_secondTimer in
+    _secondTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
+    [[NSRunLoop currentRunLoop] addTimer:_secondTimer forMode:NSRunLoopCommonModes];
+}
+
+#pragma mark 一秒一次的timer检测
+- (void)timerChange{
+   
 }
 
 - (void)didClickButFun