首页 > 代码库 > 语音(LCVoiceHudDemo)
语音(LCVoiceHudDemo)
代码:
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. voice = [[LCVoice alloc] init]; UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(self.view.frame.size.width/2-50, self.view.frame.size.height-100, 100, 100); [button setTitle:@"录制" forState:UIControlStateNormal]; [button addTarget:self action:@selector(recordStart) forControlEvents:UIControlEventTouchDown]; [button addTarget:self action:@selector(recordEnd) forControlEvents:UIControlEventTouchUpInside]; [button addTarget:self action:@selector(recordCancel) forControlEvents:UIControlEventTouchUpOutside]; [self.view addSubview:button];}-(void) recordStart{ [voice startRecordWithPath:[NSString stringWithFormat:@"%@/Documents/MySound.caf", NSHomeDirectory()]];}-(void) recordEnd{ [voice stopRecordWithCompletionBlock:^{ if (voice.recordTime > 0.0f) { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"\nrecord finish ! \npath:%@ \nduration:%f",voice.recordPath,voice.recordTime] delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil]; [alert show]; } }];}-(void) recordCancel{ [voice cancelled]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:@"取消了" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil]; [alert show];}
语音(LCVoiceHudDemo)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。