播放 .caf 文件:在模拟器中工作正常,但在 iPhone 中不行
我正在建造一个录音机。重新编码和播放在模拟器上运行良好。但在 iPhone 上它不起作用。 (我按照 iPhoneOSProgrammingGuide/AudioandVideoTechnologies)
printf("%s(player)\n",[[self.soundFileURL absoluteString] UTF8String]);
AVAudioPlayer *newPlayer =
[[AVAudioPlayer alloc] initWithContentsOfURL: self.soundFileURL error: nil];
if([self.soundFileURL isFileURL]){
printf("isFileURL\n");
}
self.player = newPlayer;
[newPlayer release];
[player prepareToPlay];
[player setDelegate: self];
//recorderLabel.text=@"Playing..";
[player play];
printf("playing..\n");
调试器输出为 文件://localhost/var/mobile/Applications/9A607A45-974B-4E9F-9839-FD21B3BC9DD8/Documents/1251828741.caf(播放器) 是文件URL 玩..
I'm building a voice recorder. Recoding and playing works fine on simulator. But on iphone it doesn't work. (I followed the exact steps as mentioned in iPhoneOSProgrammingGuide/AudioandVideoTechnologies)
printf("%s(player)\n",[[self.soundFileURL absoluteString] UTF8String]);
AVAudioPlayer *newPlayer =
[[AVAudioPlayer alloc] initWithContentsOfURL: self.soundFileURL error: nil];
if([self.soundFileURL isFileURL]){
printf("isFileURL\n");
}
self.player = newPlayer;
[newPlayer release];
[player prepareToPlay];
[player setDelegate: self];
//recorderLabel.text=@"Playing..";
[player play];
printf("playing..\n");
The debugger out put is
file://localhost/var/mobile/Applications/9A607A45-974B-4E9F-9839-FD21B3BC9DD8/Documents/1251828741.caf(player)
isFileURL
playing..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
iPhone OS 设备上没有与 iPhone OS 模拟器相同的可用音频编解码器。在我的项目中,我在播放以一种方式编码的
.caf
文件时遇到问题,但不是另一种方式……一些尝试和错误将在这里有所帮助(我最终使用了 16BLE PCM)。我会尝试更改录制的音频文件的编码,以尝试找到设备支持的音频编解码器。
The iPhone OS on-device does not have the same audio codecs available to it that the iPhone OS in-simulator does. In my projects I have had problems playing back
.caf
files encoded one way but not another... a bit of trial and error will help here (I ended up using 16BLE PCM).I would try altering the recorded audio file's encoding in an attempt to find an audio codec supported by the device.
确保 iPhone 上的声音未关闭。
将以下内容添加到您的委托(自己):
这可能会给您一些线索。
Make sure sound isn't turned off on the iPhone.
Add the following to your delegate (self):
This might give you some clues.
iPhone 的 .caf 文件需要编码为单声道而不是立体声通道,然后它才适用于 iPhone。
.caf file for iPhone need to be encoded as a mono channel and not with a stereo channel then only it will work with iPhone.