A tool can record mp3 file on iOS
// 录制/继续录制音频
- (IBAction)recorder:(UIButton *)sender {
MXMp3Recorder *recorder = MXMp3Recorder.shareInstance;
if (recorder.recordStatus == MXRecorderRecordStatusPause) {
// 继续录制音频
[recorder resumeRecording];
return;
}
recorder = [MXMp3Recorder recorderWithCachePath:nil delegate:self];
// 开始录制音频
[recorder startRecordingAndDecibelUpdate:NO];
}
// 暂停录制
- (IBAction)pauseRecording:(UIButton *)sender {
[MXMp3Recorder.shareInstance pauseRecording];
}
// 停止录制
- (IBAction)stopRecordering:(UIButton *)sender {
[MXMp3Recorder.shareInstance stopRecording];
}
// 取消录制
- (IBAction)cancelRecordering:(UIButton *)sender {
[MXMp3Recorder.shareInstance cancelRecording];
}
A tool can play mp3 file on iOS
// 播放本地音频
- (IBAction)play:(UIButton *)sender {
if (![NSFileManager.defaultManager fileExistsAtPath:_mp3FilePath]) {
return;
}
MXAVAudioPlayer *player = MXAVAudioPlayer.shareInstance;
if (player.playStatus == MXAVAudioPlayerPlayStatusPause) {
// 继续播放音频
[player resumeAudioPlayer];
return;
}
player = [MXAVAudioPlayer playerWithCachePath:nil delegate:self];
[player playAudioWithURLString:_mp3FilePath];
}
// 暂停播放音频
- (IBAction)pausePlaying:(UIButton *)sender {
[MXAVAudioPlayer.shareInstance pauseAudioPlayer];
}
// 停止播放音频
- (IBAction)stopPlaying:(UIButton *)sender {
[MXAVAudioPlayer.shareInstance stopAudioPlayer];
}