我想播放从互联网加载的声音文件,所以我尝试从 iPhone SDK SpeakHere 示例开始。我录制了声音,然后保存并上传到互联网,我可以下载该文件并通过声音工具毫无问题地播放。但是,当我尝试从 SpeakHere 播放该 URL 时,出现错误程序收到信号:“EXC_BAD_ACCESS”
。
经过跟踪,我发现-[AudioPlayercalculateSizesFor:]
中,将bufferByteSize
设置为一个巨大的数字806128768,导致缓冲区分配失败。
那是因为
AudioFileGetProperty(audioFileID, kAudioFilePropertyPacketSizeUpperBound, &propertySize, &maxPacketSize);
返回的maxPacketSize
是806128768。
我想知道如何使 AudioFileGetProperty
工作。
我使用这种方式在-[AudioViewController playOrStop]
方法中设置URL:
// AudioPlayer *thePlayer = [[AudioPlayer alloc] initWithURL: self.soundFileURL];
AudioPlayer *thePlayer = [[AudioPlayer alloc] initWithURL:
[NSURL URLWithString: @"http://chineseresume.com/localbiz/uploads/myfilename_7_Recording.caf"]];
非常欢迎任何建议。
最佳答案
是的,您需要使用Audio File Stream Services直接从互联网上玩。
我发现“AudioFileStreamExample”示例很有用,应该安装在
/Developer/Examples/CoreAudio/Services/AudioFileStreamExample/
此外,Matt Gallagher 有一篇名为“Streaming and playing an MP3 stream”的文章,其中包含 iPhone 示例代码。没仔细看,不过好像对你有帮助。
关于iphone - SpeakHere 示例无法播放从互联网加载的声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/293929/