AVAudioRecorder 文件无法播放(除非使用 VLC)
好的。我想我在这里遗漏了一些东西,我是核心音频的新手,但我已经搜索过 苹果文档和网络上的其他内容都无济于事。我也在苹果开发论坛上发布了同样的问题,但没有得到回复。我希望 StackOverflow 社区能够帮助我。
我正在使用 AVAudioRecorder 和 AVAudioPlayer 录制音频并播放它。我的应用程序还使用文件共享,以便用户可以导出音频并在其他地方播放。这就是我的问题所在。我正在使用 AAC 编码进行录制,但该文件不会导入到 iTunes 中。它使用 VLC 播放得很好,并查看媒体信息,它的编解码器是我所期望的 mp4a。
在网上阅读,听起来 AAC 需要一个 mp4a 包装器。任何人都可以启发我或指导我了解一些有关此的信息吗?我可以使用 API 或第三方库吗?
我玩过 SpeakHere 和 ExtAudioFileConvertTest 示例,添加了文件共享, 录制为 AAC,但它们仍然无法在 iTunes 中播放。
这是我的录音代码。非常感谢任何建议或指导。谢谢!
NSDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax],AVEncoderAudioQualityKey,
nil];
...
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL: soundFileURL
settings: recordSettings
error: &error];
Ok. I think I'm missing something here and I'm new to Core Audio but I have scoured the
Apple documents and the rest of the web to no avail. I've also posted this same question to the apple dev forums and got no replies. I'm hoping the StackOverflow community can help me out.
I'm recording audio and playing it back just fine using AVAudioRecorder and AVAudioPlayer. My app also uses file sharing so the user can export the audio and play it elsewhere. This is where my issue comes in. I'm recording using AAC encoding but the file will not import into iTunes. It plays fine using VLC and looking at the media information its' codec is mp4a which I expected.
Reading on the web its sounding like the AAC needs a mp4a wrapper. Can anyone enlighten me or direct me to some info on this? Possibly an API or 3rd party library I can use?
I've played with the SpeakHere and ExtAudioFileConvertTest examples, added file sharing,
recorded as AAC but they still won't play in iTunes.
Here's my recording code. Very grateful for any suggestions or guidance. Thanks!
NSDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax],AVEncoderAudioQualityKey,
nil];
...
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL: soundFileURL
settings: recordSettings
error: &error];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在苹果论坛上一些人的帮助下解决了这个问题。我所要做的就是将文件扩展名设置为 m4a!手动更改扩展名并尝试在 iTunes 中播放不起作用。 AVAudioRecorder 中的某些内容似乎使用扩展名来正确编码文件。只要正确设置扩展,它就能完美地工作。希望这可以帮助其他人在未来。
Figured this out with some help from some on the Apple forums. All I had to do was set the filename extension to m4a! Changing the extension manually and trying to play in iTunes does not work. Something under the covers in AVAudioRecorder seems to use the extension to encode the file correctly. Just set the extension correctly and it works beautifully. Hope this helps someone else out in the future.