iOS 音频录制、播放,使用音频处理框架The Amazing Audio Engine实现音频录制播放 —— HERO博客

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
评论 36
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值