录音
来源:互联网 发布:天谕捏脸嘴巴数据 编辑:程序博客网 时间:2024/04/27 20:08
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController :UIViewController<AVAudioPlayerDelegate>
{
NSURL *recordedFile;
AVAudioPlayer *player;
AVAudioRecorder *recorder;
BOOL isRecording;
}
@property (nonatomic)BOOL isRecording;
@property (weak, nonatomic) IBOutletUIButton *playStateButton;
@property (weak, nonatomic) IBOutletUIButton *recordStateButton;
- (IBAction)playStateButtonAction:(id)sender;
- (IBAction)recordStateButtonAction:(id)sender;
@end
- (void)viewDidLoad
{
[superviewDidLoad];
self.isRecording =NO;
[self.playStateButtonsetEnabled:NO];
self.playStateButton.titleLabel.alpha = 0.5;
recordedFile = [NSURLfileURLWithPath:[NSTemporaryDirectory()stringByAppendingString:@"RecordedFile"]];
AVAudioSession *session = [AVAudioSessionsharedInstance];
NSError *sessionError;
[session setCategory:AVAudioSessionCategoryPlayAndRecorderror:&sessionError];
if (session ==nil) {
NSLog(@"Error creating session :%@",[sessionErrordescription]);
}else
[sessionsetActive:YESerror:nil];
}
- (IBAction)playStateButtonAction:(id)sender
{
// If the state is laying ,pause and achange playButton text to "Play"
if ([playerisPlaying]) {
[self.playStateButtonsetTitle:@"Play"forState:UIControlStateNormal];
}
// If the track is not player ,play the track and change the play button to "Pause"
else{
[playerplay];
[self.playStateButtonsetTitle:@"Pause"forState:UIControlStateNormal];
}
}
- (IBAction)recordStateButtonAction:(id)sender
{
// if the app is not recording,we want to start recording,disable the paly button,and make the record button say "STOP"
if (!self.isRecording) {
self.isRecording =YES;
[self.recordStateButtonsetTitle:@"Stop"forState:UIControlStateNormal];
[self.playStateButtonsetEnabled:NO];
[self.playStateButton.titleLabelsetAlpha:0.5];
recorder = [[AVAudioRecorderalloc]initWithURL:recordedFilesettings:nilerror:nil];
[recorder prepareToRecord];
[recorder record];
player =nil;
}
// if the app is recording ,we want to stop recrding,enable the play button,and make the record button say "Record"
else{
self.isRecording =NO;
[self.recordStateButtonsetTitle:@"record"forState:UIControlStateNormal];
[self.playStateButtonsetEnabled:YES];
[self.playStateButton.titleLabelsetAlpha:1];
[recorder stop];
NSError *playerError;
player = [[AVAudioPlayeralloc]initWithContentsOfURL:recordedFileerror:&playerError];
if (player ==nil) {
NSLog(@"Error creating player :%@",[playerErrordescription]);
}
player.delegate =self;
}
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
[self.playStateButtonsetTitle:@"Play"forState:UIControlStateNormal];
}
- 录音
- 录音
- 录音
- 录音
- 录音
- 录音
- 录音
- 录音
- 录音
- 录音
- 网页录音,html5录音
- DirectSound 录音
- Android 录音
- MCI录音
- android 录音
- Android 录音
- caf录音
- android 录音
- Unioning of the Buffer Cache and Journaling Layers
- 马云最新演讲:勤奋与努力是不够的,企业未来需进行三大变革
- python十个项目之----万能的XML
- 常用的正则表达式
- [JAVA]定时任务之-Quartz使用篇
- 录音
- 分布式集群环境hadoop1.2.0、hbase0.94.4、zookeeper、elasticsearch搭建2
- 杭电 2037
- Json概述以及python对json的相关操作
- 网络安全,选什么方案?
- vmWare-workstation的磁盘大小调整
- Android:将View的内容映射成Bitmap转图片导出
- PCM WAVE格式详解及用C语言实现wave文件的读取
- freeswitch离线对帐话单的产生及保存方式及配置说明