回顾这一个月以来所学到的ios知识
来源:互联网 发布:紫峰秒杀软件 编辑:程序博客网 时间:2024/05/23 01:13
1.ios的开端---做一个手机端真实功能的录音机
- (void)viewDidLoad {
[superviewDidLoad];
dataSource = [selffilesOfPath];
NSLog(@"dataSource:%@",dataSource);
tableview = [[UITableViewalloc]initWithFrame:CGRectMake(0,50,375,500)];
self.title =@"Record Voice List";
[tableviewsetDelegate:self];
[tableviewsetDataSource:self];
[self.viewaddSubview:tableview];
recordButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
recordButton.frame =CGRectMake(45,590,136,37);
[recordButtonsetTitle:@"RecordVoice"forState:UIControlStateNormal];
[recordButtonaddTarget:selfaction:@selector(recordAudio)forControlEvents:UIControlEventTouchUpInside];
recordButton.backgroundColor = [UIColorredColor];
[self.viewaddSubview:recordButton];
playButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
playButton.frame =CGRectMake(193,590,136,37);
[playButtonsetTitle:@"Play"forState:UIControlStateNormal];
[playButtonaddTarget:selfaction:@selector(playAudio)forControlEvents:UIControlEventTouchUpInside];
playButton.backgroundColor = [UIColorgreenColor];
[self.viewaddSubview:playButton];
}
// 录音功能的初始化
- (void) initRecordVoice{
[selfvoiceCheck];
NSURL *soundFileURL = [NSURLfileURLWithPath:[[selfdocumentsPath]stringByAppendingString:[selfgenerateFileName]]];
NSLog(@"soundFileURL:%@",soundFileURL);
NSDictionary *soundSetting;
soundSetting = [NSDictionarydictionaryWithObjectsAndKeys:
[NSNumbernumberWithFloat:44100.0],AVSampleRateKey,
[NSNumbernumberWithInt:kAudioFormatMPEG4AAC],AVFormatIDKey,
[NSNumbernumberWithInt:2],AVNumberOfChannelsKey,
[NSNumbernumberWithInt:AVAudioQualityHigh],
AVEncoderAudioQualityKey,nil];
self.audioRecorder = [[AVAudioRecorderalloc]initWithURL:soundFileURLsettings:soundSettingerror:nil];
//开启音量检测
self.audioRecorder.meteringEnabled =YES;
self.audioRecorder.delegate =self;
}
然后是存文件问题和为新文件命名,我是采用日期来为文件命名// 设置录音文件的命名
- (NSString *)generateFileName{
NSDate *today = [NSDatedate];
NSLog(@"%@",today);
NSDateFormatter *df = [[NSDateFormatteralloc]init];
[df setDateFormat:@"yyyyMMddHHmmss"];
NSString *s1 = [df stringFromDate:today];
//NSDate *date = [df dateFromString:s1];
s1 = [s1 stringByAppendingString:@".caf"];
NSString *name = [@"/"stringByAppendingString:s1];
NSLog(@"%@",name);
return name;
}
// 重新加载数据源并刷新tableview
- (void)reloadTableView{
dataSource = [selffilesOfPath];
[tableviewreloadData];
}
// 控制录制音频的功能
- (void)recordAudio{
if([self.recordButton.titleLabel.textisEqualToString:@"RecordVoice"]){
[selfinitRecordVoice];
[self.audioRecorderrecord];
NSLog(@"%@",self.audioRecorder);
[self.recordButtonsetTitle:@"StopRecord"forState:UIControlStateNormal];
[self.playButtonsetEnabled:NO];
}else{
[self.audioRecorderstop];
[self.recordButtonsetTitle:@"RecordVoice"forState:UIControlStateNormal];
[self.playButtonsetEnabled:YES];
[selfreloadTableView];
}
}
// 控制播放音频的功能
- (void)playAudio{
if([self.playButton.titleLabel.textisEqualToString:@"Play"]){
[self.audioPlayerplay];
[self.playButtonsetTitle:@"Pause"forState:UIControlStateNormal];
[self.recordButtonsetEnabled:NO];
}else{
[self.audioPlayerpause];
[self.playButtonsetTitle:@"Play"forState:UIControlStateNormal];
[self.recordButtonsetEnabled:YES];
}
}
// 返回数据的行数
- (NSInteger)tableView:(UITableView*) tableView numberOfRowsInSection:(NSInteger)section{
return [dataSourcecount];
}
// 给列表的表格添加数据
- (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
static NSString* identifier =@"basis-cell";
UITableViewCell* cell = [tableViewdequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier];
}
cell.textLabel.text = [dataSourceobjectAtIndex:indexPath.row];
return cell;
}
// 给列表的行选中添加事件
- (void)tableView:(UITableView*)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString* message =[@"/"stringByAppendingString:[dataSourceobjectAtIndex:indexPath.row]];
//Load the new sound in the audioPlayer for playback
NSURL *soundFileURL = [NSURLfileURLWithPath:[[selfdocumentsPath]stringByAppendingString:message]];
self.audioPlayer = [[AVAudioPlayeralloc]initWithContentsOfURL:soundFileURLerror:nil];
[self.audioPlayerplay];
NSLog(@"audioPlayer:%@",self.audioPlayer);
}
// 设置标题栏的标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return@"Play List";
}
//获取指定目录的文件,存在数组中
- (NSArray *)filesOfPath{
NSFileManager *fm = [NSFileManagerdefaultManager];
NSString *path = [selfdocumentsPath];
NSArray *files = [fm contentsOfDirectoryAtPath:path error:nil];
return files;
}
//获取指定目录的路径
- (NSString *) documentsPath{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsdir = [paths objectAtIndex:0];
return documentsdir;
}
反思:
- 回顾这一个月以来所学到的ios知识
- ios 一个月以来的总结。。。
- 来到兄弟连这一个月以来的感受
- 最近所学网络知识的一个总结
- 关于一个月以来找工作的经验总结
- 产品经理一个月以来的随笔
- 9.18所学的知识
- 在ThoughtWorks实习六个月所学到的
- 我在微软8个月所学到的
- iOS description 方法 引发的所学的大学计算机知识
- 大学以来的成长回顾
- 当一个管理者两个月以来的总结
- blog一个月以来的流量和访问统计结果
- 【原创】关于一个月以来应聘的感想
- 最近一个月以来找工作的一些感受(转载)
- 入职以来一个月的心得体悟
- 如何记住所学的知识
- HTML实战所学的知识
- 包子的 oracle 学习笔记---ORA异常原因与解决办法
- shell 文件分类
- UIControl及其子类
- Smarty标签运算,控制结构[if,for,foreach,section,while]
- Javascript使用方括号([])引用对象的属性和方法,[]和.的区别
- 回顾这一个月以来所学到的ios知识
- String类实现
- Visual SourceSafe基本操作
- hive配置元数据库为postgresql小结
- JS模块化工具requirejs教程(二):基本知识
- 5-2 然后是几点
- HDU1039 Easier Done Than Said?(java)
- 数据持久化
- 支持向量机通俗导论(理解SVM的三层境界)