您好,登錄后才能下訂單哦!
在iOS的基礎(chǔ)類庫中, 提供了AVFoundation FrameWork,即Audio/Video基礎(chǔ)類庫,通過使用這個類庫,可以非常容易的在應(yīng)用程序錄制,播放視頻,音頻等。
在錄制前要初始化 AVAudioRecorder *recorder;
//錄音設(shè)置
NSMutableDictionary *recordSetting = [[[NSMutableDictionaryalloc]init] autorelease];
//設(shè)置錄音格式 AVFormatIDKey==kAudioFormatLinearPCM
[recordSetting setValue:[NSNumbernumberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
//設(shè)置錄音采樣率(Hz) 如:AVSampleRateKey==8000/44100/96000(影響音頻的質(zhì)量)
[recordSetting setValue:[NSNumbernumberWithFloat:44100] forKey:AVSampleRateKey];
//錄音通道數(shù) 1 或 2
[recordSetting setValue:[NSNumbernumberWithInt:1] forKey:AVNumberOfChannelsKey];
//線性采樣位數(shù) 8、16、24、32
[recordSetting setValue:[NSNumbernumberWithInt:16] forKey:AVLinearPCMBitDepthKey];
//錄音的質(zhì)量
[recordSetting setValue:[NSNumbernumberWithInt:AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey];
NSString *strUrl = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSURL *url = [NSURLfileURLWithPath:[NSStringstringWithFormat:@"%@/lll.aac", strUrl]];
urlPlay = url;
NSError *error;
//初始化
recorder = [[AVAudioRecorderalloc]initWithURL:url settings:recordSetting error:&error];
//開啟音量檢測
recorder.meteringEnabled = YES;
recorder.delegate = self;
錄制完后保存
- (IBAction)btnUp:(id)sender
{
double cTime = recorder.currentTime;
if (cTime > 2) {//如果錄制時間<2 不發(fā)送
NSLog(@"發(fā)出去");
}else {
//刪除記錄的文件
[recorderdeleteRecording];
//刪除存儲的
}
[recorderstop];
[timerinvalidate];
}
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。