自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

詳解IPhone之 AVAudioRecorder 代碼實現(xiàn)

移動開發(fā) iOS
本文介紹的是詳解IPhone之 AVAudioRecorder 代碼實現(xiàn),很好的一篇文章,與友們分享一下,我們一起來看內(nèi)容。

詳解IPhoneAVAudioRecorder 代碼實現(xiàn)是本文要介紹的內(nèi)容,內(nèi)容不多,基本屬于代碼實現(xiàn)。我們來看詳細內(nèi)容。

#import <AVFoundation/AVFoundation.h>  需要引入

  1. //獲取document目錄的路徑  
  2. - (NSString*) documentsPath {  
  3.  if (! _documentsPath) {  
  4.   NSArray *searchPaths =  
  5.    NSSearchPathForDirectoriesInDomains 
  6.    (NSDocumentDirectory, NSUserDomainMask, YES);  
  7.   _documentsPath = [searchPaths objectAtIndex: 0];  
  8.   [_documentsPath retain];  
  9.  }  
  10.  return _documentsPath;  
  11. }  
  12. //(document目錄的路徑)  
  13.  NSString *destinationString = [[self documentsPath]  
  14.    stringByAppendingPathComponent:filenameField.text];  
  15.  NSURL *destinationURL = [NSURL fileURLWithPath: destinationString];  
  16.  
  17. //初始化AVAudioRecorder  
  18.  NSError *recorderSetupError = nil;  
  19.  AVAudioRecorder audioRecorder = [[AVAudioRecorder alloc] initWithURL:destinationURL  
  20.    settings:recordSettings error:&recorderSetupError];   
  21.  [recordSettings release]; 

第二個參數(shù)  settings是一個容納鍵值對的NSDictionary有四種一般的鍵

1、一般的音頻設(shè)置

2、線性PCM設(shè)置

3、編碼器設(shè)置

4、采樣率轉(zhuǎn)換設(shè)置

  1. NSMutableDictionary  需要加入五個設(shè)置值(線性PCM)  
  2.  
  3. NSMutableDictionary *recordSettings =  
  4.   [[NSMutableDictionary alloc] initWithCapacity:10];  
  5.  
  6.   //1 ID號  
  7.   [recordSettings setObject:  
  8.    [NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey];  
  9.   float sampleRate =  
  10.    [pcmSettingsViewController.sampleRateField.text floatValue];  
  11.   //2 采樣率  
  12.   [recordSettings setObject:  
  13.    [NSNumber numberWithFloat:sampleRate] forKey: AVSampleRateKey];  
  14.     
  15.   //3 通道的數(shù)目  
  16.   [recordSettings setObject:  
  17.    [NSNumber numberWithInt:  
  18.     (pcmSettingsViewController.stereoSwitch.on ? 2 : 1)]  
  19.    forKey:AVNumberOfChannelsKey];  
  20.   int bitDepth =  
  21.    [pcmSettingsViewController.sampleDepthField.text intValue];  
  22.     
  23.   //4 采樣位數(shù)  默認 16  
  24.   [recordSettings setObject:  
  25.    [NSNumber numberWithInt:bitDepth] forKey:AVLinearPCMBitDepthKey];  
  26.     
  27.   //5  
  28.   [recordSettings setObject:  
  29.    [NSNumber numberWithBool:  
  30.      pcmSettingsViewController.bigEndianSwitch.on]  
  31.     forKey:AVLinearPCMIsBigEndianKey];  
  32.  
  33.  
  34.   //6 采樣信號是整數(shù)還是浮點數(shù)  
  35.   [recordSettings setObject:  
  36.    [NSNumber numberWithBool:  
  37.      pcmSettingsViewController.floatingSamplesSwitch.on]  
  38.     forKey:AVLinearPCMIsFloatKey]; 

AVAudioRecorder成功創(chuàng)建后,使用他非常直接.它的三個基本方法如下

  1. -(void) startRecording {  
  2.  [audioRecorder record];  
  3. }  
  4.  
  5. -(void) pauseRecording {  
  6.  [audioRecorder pause];  
  7.  recordPauseButton.selected = NO;  
  8. }  
  9.  
  10. -(void) stopRecording {  
  11.  [audioRecorder stop];  

小結(jié):詳解IPhoneAVAudioRecorder的內(nèi)容介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-08-11 17:32:51

iPhone視圖

2011-07-18 14:39:53

iPhone SDK UIKit

2011-07-28 10:11:54

iPhone開發(fā) 備忘

2011-08-18 10:59:57

iPhone開發(fā)消息通信NSNotificat

2011-08-17 15:19:38

iPhone應用數(shù)據(jù)

2011-08-18 15:40:20

iPhone文本切頁

2011-07-27 11:19:33

iPhone UITableVie

2011-08-12 14:04:53

iPhone動畫

2011-07-29 15:47:21

iPhone開發(fā) Objective- C

2011-08-16 15:36:47

iPhone應用測試

2011-07-29 13:55:10

IPhone 動畫

2011-07-25 14:44:41

iPhone iPhone開發(fā) 截屏

2011-07-20 17:29:12

iPhone 網(wǎng)絡(luò)

2011-06-03 10:19:59

iphone Objective-

2011-08-18 09:44:33

iPhone SDK儀表控件UIDialView

2021-05-08 07:57:17

ServletFilter設(shè)計模式

2011-08-15 11:23:41

iPhone開發(fā)循環(huán)滾動UIScrollVie

2011-08-01 13:13:19

iPhone開發(fā) 圖片

2011-08-08 10:42:46

iPhone UITableVie 分頁

2011-07-27 15:47:09

iPhone Simulator 文件
點贊
收藏

51CTO技術(shù)棧公眾號