2014-09-30 38 views
1

我已經實現AVAudiorecorder錄音和播放語音10秒。它與iOS 7工作正常。但是當我在ios8上運行相同的代碼,它不工作請幫助。 這是一個源代碼。AVAudioRecorder不工作在iOS8

//Below is my code for recording and Playing. 

//Here is the Recording code which records sound for 10 secs 

AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
NSError *err = nil; 
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err]; 
if(err){ 
    return; 
} 
[audioSession setActive:YES error:&err]; 
err = nil; 

    // Setup audio recording 
recordSetting = @{AVFormatIDKey: @(kAudioFormatMPEG4AAC), 
           AVEncoderAudioQualityKey: @(AVAudioQualityLow), 
           AVNumberOfChannelsKey: @1, 
           AVSampleRateKey: @22050.0f}; 

recorderFilePath = [NSString stringWithFormat:@"%@/MySound.wave", DOCUMENTS_FOLDER]; 
NSData *postData = [NSData dataWithContentsOfFile:recorderFilePath]; 
NSURL *url = [NSURL fileURLWithPath:recorderFilePath];err = nil; 
NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&err]; 

if(audioData) 
{NSFileManager *fm = [NSFileManager defaultManager]; 
    [fm removeItemAtPath:[url path] error:&err];} 
err = nil; 
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err]; 

//prepare to record 
[recorder setDelegate:self]; 
[recorder prepareToRecord]; 
recorder.meteringEnabled = YES; 


//Please help me out and tell if i have to add/modify something because it is working in ios7. 
+0

你們是不是要做到這一點在小部件

[recorder recordForDuration:(NSTimeInterval) 10]; 

打個電話?你爲什麼用widget標籤標記你的文章? – JAL 2014-09-30 21:42:28

回答

1

看起來你的代碼片段沒有錯。 我也使用大致相同的代碼在我的iPhone上進行註冊。 我的代碼唯一的區別是,以啓動註冊10秒

相關問題