【发布时间】:2011-11-30 19:51:17
【问题描述】:
问题:通过 http 传输音频后无法录制声音。
我遇到的问题是使用本指南流式传输 mp3 后我无法再录制声音:http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html
在播放任何 mp3 之前,我可以完美地录制声音。只有在我使用指南流式传输 mp3 后,我的 ios 应用程序才能再录制声音。
我想知道你们中是否有人可能以前遇到过这个问题,或者有任何预感为什么会出现这个问题?我会继续发布我的录制代码,以防万一你们需要查看它。
在我流式传输任何 mp3 之前,audioRecorderDidFinishRecording 总是在录制完成后触发。
在我流式传输 mp3 后,audioRecorderDidFinishRecording 不会在录制完成后触发。
提前感谢您的帮助。
// #########################
NSURL *soundFileUrl = [NSURL fileURLWithPath:self.recordFilePath];
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithInt:AVAudioQualityMax], AVEncoderAudioQualityKey,
[NSNumber numberWithInt:24], AVEncoderBitRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSNumber numberWithFloat:22050.0f], AVSampleRateKey,
nil];
NSError *error = nil;
self.recorder = [[AVAudioRecorder alloc] initWithURL:soundFileUrl settings:recordSettings error:&error];
if (error) {
NSLog(@"%@", error);
} else{
self.recorder.delegate = self;
[self.recorder prepareToRecord];
[self.recorder record];
self.recordCountdown = [NSTimer scheduledTimerWithTimeInterval:(1.0/1.0) target:self selector:@selector(updateLabelCountdown) userInfo:nil repeats:YES];
}
// delegate for finish recording with success and failure
- (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag {
NSLog(@"record did finish flag - %d", flag);
}
- (void) audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error {
NSLog(@"error record - %@", [error localizedDescription]);
}
【问题讨论】:
-
是的。我最终根本没有使用那个外部库。我最终使用 UIWebView 流式传输音频。我认为外部库占用了一些关键的音频资源,并且在播放完音频文件后永远不会释放它。
标签: iphone ios stream avaudioplayer avaudiorecorder