在ios中编写程序实现录音功能
2013-10-26 21:31
405 查看
#import <UIKit/UIKit.h>
#import "AVFoundation/AVFoundation.h"
@interface AudioRecoderViewController : UIViewController
{
UILabel *label;
AVAudioRecorder *recorder; //定义专门录制的类AVAudioRecoder
AVAudioPlayer *player;
}
@property(nonatomic,retain) AVAudioRecorder *recorder;
@property(nonatomic,retain) AVAudioPlayer *player;
@end
#import "AudioRecoderViewController.h"
@interface AudioRecoderViewController ()
@end
@implementation AudioRecoderViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)loadView{
//定义UIView
UIView *view=[[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame] ;
view.backgroundColor=[UIColor purpleColor];
self.view=view;
//初始化label
label=[[UILabel alloc]initWithFrame:CGRectMake(90, 40, 160, 40)];
label.text=@"等待录制";
label.textColor=[UIColor greenColor];
label.textAlignment=NSTextAlignmentCenter;
[self.view addSubview:label];
//定义按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(90, 100, 160, 40);
[button setTitle:@"开始录制" forState:UIControlStateNormal];
[button addTarget:self action:@selector(startRecoder) forControlEvents:UIControlEventTouchUpInside];
//添加显示
[self.view addSubview:button];
//定义按钮
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn2.frame = CGRectMake(90, 160, 160, 40);
[btn2 setTitle:@"停止录制" forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(stopRecoder) forControlEvents:UIControlEventTouchUpInside];
//添加显示
[self.view addSubview:btn2];
//定义按钮
UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn3.frame = CGRectMake(90, 220, 160, 40);
[btn3 setTitle:@"播放录制" forState:UIControlStateNormal];
[btn3 addTarget:self action:@selector(startRecoderPlay) forControlEvents:UIControlEventTouchUpInside];
//添加显示
[self.view addSubview:btn3];
}
-(void)startRecoder{
//设置label的显示 显示为正在录制
label.textColor=[UIColor redColor];
label.text=@"录制中...";
label.textAlignment=NSTextAlignmentCenter;
//判断当前的录制状态和播放状态
if (recorder.isRecording)
{
[recorder stop];
}
if (player.isPlaying)
{
[recorder stop];
}
NSError
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import "AVFoundation/AVFoundation.h"
@interface AudioRecoderViewController : UIViewController
{
UILabel *label;
AVAudioRecorder *recorder; //定义专门录制的类AVAudioRecoder
AVAudioPlayer *player;
}
@property(nonatomic,retain) AVAudioRecorder *recorder;
@property(nonatomic,retain) AVAudioPlayer *player;
@end
#import "AudioRecoderViewController.h"
@interface AudioRecoderViewController ()
@end
@implementation AudioRecoderViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)loadView{
//定义UIView
UIView *view=[[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame] ;
view.backgroundColor=[UIColor purpleColor];
self.view=view;
//初始化label
label=[[UILabel alloc]initWithFrame:CGRectMake(90, 40, 160, 40)];
label.text=@"等待录制";
label.textColor=[UIColor greenColor];
label.textAlignment=NSTextAlignmentCenter;
[self.view addSubview:label];
//定义按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(90, 100, 160, 40);
[button setTitle:@"开始录制" forState:UIControlStateNormal];
[button addTarget:self action:@selector(startRecoder) forControlEvents:UIControlEventTouchUpInside];
//添加显示
[self.view addSubview:button];
//定义按钮
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn2.frame = CGRectMake(90, 160, 160, 40);
[btn2 setTitle:@"停止录制" forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(stopRecoder) forControlEvents:UIControlEventTouchUpInside];
//添加显示
[self.view addSubview:btn2];
//定义按钮
UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn3.frame = CGRectMake(90, 220, 160, 40);
[btn3 setTitle:@"播放录制" forState:UIControlStateNormal];
[btn3 addTarget:self action:@selector(startRecoderPlay) forControlEvents:UIControlEventTouchUpInside];
//添加显示
[self.view addSubview:btn3];
}
-(void)startRecoder{
//设置label的显示 显示为正在录制
label.textColor=[UIColor redColor];
label.text=@"录制中...";
label.textAlignment=NSTextAlignmentCenter;
//判断当前的录制状态和播放状态
if (recorder.isRecording)
{
[recorder stop];
}
if (player.isPlaying)
{
[recorder stop];
}
NSError
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- 编写程序,实现strcmp()相同功能myStrcmp()函数
- iOS录音功能的实现
- IOS程序开发之跳转短信发送界面实现发送短信功能
- iOS 录音功能的实现
- iOS语音消息功能实现,录音/播放录音
- 编写一个程序,将字符数组s2中的全部字符复制到s1中。即实现strcpy函数功能
- 利用模板类编写一个程序,实现双向链表的插入、删除、查找、显示的功能。
- iOS 录音功能的实现
- 编写一个程序,实现“全部替换”功能
- 编写一个控制台程序,实现以下功能
- 【学习ios之路:C语言】小程序:实现类似ATM取款机功能.
- 编写一个程序 提示用户输入三个数集,每个包括5个数 实现以下功能 (图)
- iOS录音功能的实现
- iOS之利用系统自带API实现录音功能
- 编写程序,实现strcmp()相同功能myStrcmp()函数
- 小明去美国旅游,美国温度以华氏温度计量,她需要将华氏温度转换为摄氏温度,编写程序实现此功能. 要求: 从控制台输入华氏温度信息,并且分别打印最后的华氏温度和摄氏温度的结果
- ios 定位新功能----在程序中实现定位功能
- 编写一个程序实现strcat函数的功能
- iOS 录音功能的实现
- 在μPD78F0485单片机实验盒上编写程序实现在LCD上显示日历功能