当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - AVAudioRecorder failing on iPhone 4 after playing audio in UIWebView

问题描述:

There is a UIWebView that has an <audio> tag in it. The user can use it to play an audio clip.

NSString *audiopath = [[NSBundle mainBundle] pathForResource:@"hello" ofType:@"m4a"];

NSString *html = [NSString stringWithFormat:@"<audio src=\"file://%@\" controls />", audiopath];

[self.webView loadHTMLString:html baseURL:nil];

There is also an AVAudioRecorder that can record audio clips.

AVAudioSession *session = [AVAudioSession sharedInstance];

[session setCategory:AVAudioSessionCategoryRecord error:nil];

NSMutableDictionary *settings = [NSMutableDictionary dictionary];

[settings setValue: [NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];

[settings setValue: [NSNumber numberWithInt:AVAudioQualityLow] forKey: AVEncoderAudioQualityKey];

[settings setValue: [NSNumber numberWithFloat:8000.0f] forKey:AVSampleRateKey];

[settings setValue: [NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey]; // mono

self.audioRecorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:nil];

[self.audioRecorder prepareToRecord];

[self.audioRecorder record]; // FAILS! (Returns NO)

The audio recorder works fine until you play the voice clip from the UIWebView. From that point on, [AVAudioRecorder record] will fail. But only on iPhone4 with iOS6! iPhone 5 and iPad (iOS5 and iOS6) are all unaffected. (I haven't tried iPhone4 with iOS5- maybe this is a device-related issue?)

What could I be missing?

Here is a sample project that demonstrates the problem.

http://boxybutgood.com/catch/PlayRecord.zip

Thanks!!!!

分享给朋友:
您可能感兴趣的文章:
随机阅读: