iOS 第三方音频框架The Amazing Audio Engine使用,实现音频录制、播放,可设置配乐。
首先看一下效果图:
下面贴上核心控制器代码:
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "HWProgressHUD.h"
#import "UIImage+HW.h"
#import "AERecorder.h"
#import "HWRecordingDrawView.h"
#define KMainW [UIScreen mainScreen].bounds.size.width
#define KMainH [UIScreen mainScreen].bounds.size.height
@interface ViewController ()
@property (nonatomic, strong) AERecorder *recorder;
@property (nonatomic, strong) AEAudioController *audioController;
@property (nonatomic, strong) AEAudioFilePlayer *player;
@property (nonatomic, strong) AEAudioFilePlayer *backgroundPlayer;
@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, strong) NSMutableArray *soundSource;
@property (nonatomic, weak) HWRecordingDrawView *recordingDrawView;
@property (nonatomic, weak) UILabel *recLabel;
@property (nonatomic, weak) UILabel *recordTimeLabel;
@property (nonatomic, weak) UILabel *playTimeLabel;
@property (nonatomic, weak) UIButton *auditionBtn;
@property (nonatomic, weak) UIButton *recordBtn;
@property (nonatomic, weak) UISlider *slider;
@property (nonatomic, copy) NSString *path;
@end
@implementation ViewController
- (AEAudioController *)audioController
{
if (!_audioController) {
_audioController = [[AEAudioController alloc] initWithAudioDescription:[AEAudioController nonInterleavedFloatStereoAudioDescription] inputEnabled:YES];
_audioController.preferredBufferDuration = 0.005;
_audioController.useMeasurementMode = YES;
}
return _audioController;
}
- (NSMutableArray *)soundSource
{
if (!_soundSource) {
_soundSource = [NSMutableArray array];
}
return _soundSource;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self creatControl];
}
- (void)creatControl
{
CGFloat marginX = 30.0f;
//音频视图
HWRecordingDrawView *recordingDrawView = [[HWRecordingDrawView alloc] initWithFrame:CGRectMake(marginX, 80, KMainW - marginX * 2, 100)];
[self.view addSubview:recordingDrawView];
_recordingDrawView = recordingDrawView;
//REC
UILabel *recLabel = [[UILabel alloc] initWithFrame:CGRectMake(marginX, CGRectGetMaxY(recordingDrawView.frame) + 20, 80, 40)];
recLabel.text = @"REC";
recLabel.textColor = [UIColor redColor];
[self.view addSubview:recLabel];
_recLabel = recLabel;
//录制时间
UILabel *recordTim