2014-09-30 41 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秒

相关问题