【发布时间】:2012-10-07 21:59:22
【问题描述】:
在我的应用程序中,我使用 AVAudioRecorder 对象来允许用户录制声音文件,当用户完成录制后,他们可以通过 AVAudioPlayer 播放声音。我遇到的问题是当用户尝试播放它只播放一秒钟的音频文件时。更奇怪的是,这段代码在 iOS 5 上运行良好,但自从升级到 iOS 6 后,这个问题就开始发生了。
我已经检查了通过 iTunes 文件共享创建的文件,并且我可以在我的桌面上播放整个声音文件。
下面我粘贴了加载音频播放器的操作文件中的代码。据我所知
- (void)playRecordingBtnClk:(id)sender
{
NSLog(@"Play btn clk");
if (!isRecording) {
// disable all buttons
[_recordButton disableButton];
[_stopButton disableButton];
[_playButton disableButton];
[_saveButton disableButton];
// create the player and play the file from the beginning
if (audioPlayer) {
[audioPlayer release];
audioPlayer = nil;
}
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioRecorder.url error:&error];
audioPlayer.delegate = self;
audioPlayer.currentTime = 0.0;
[audioPlayer prepareToPlay];
if (error) {
NSLog(@"Error Playing Audio File: %@", [error debugDescription]);
return;
}
[audioPlayer play];
[self startTicker];
}
}
看来
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
方法在一秒钟后被调用,这就是音频播放器停止的原因。有人知道这里发生了什么吗?
【问题讨论】:
-
嗯...我什至没有意识到这是人们需要做的事情。我阅读了您链接的文章并接受了答案。谢谢
标签: ios ios6 avaudioplayer