Joining two CAF files together

荒凉一梦 提交于 2019-12-24 00:58:18

问题


I have the simple problem here. I have two CAF files. All I want to do is to join them to be one long audio file.

I've tried to:

  • Use the NSData class and append the audio data of both files into one. Hasn't worked. I assume some file property is not being set properly. The resulting file only plays the length of the first file.

  • Tried to set the kAudioFilePropertyAudioDataByteCount property of the resulting file in my joining process. No result.

Could anyone point me in the right direction / help me with some sample code? I have seen other people asking similar questions and going unanswered. Hoping someone would pick this up.

Your help is greatly appreciated. Thanks.


回答1:


If anyone is keen to know the answer, there is a way to do it. You have to use the AudioFiles API calls. Basically, you'd:

  • create a new audio file using AudioFileCreate with the correct parameters (bitrate etc).
  • open your first file, read the packets and write them to the newly created file.
  • open your second file and do the same. make sure your counters are not zero-ed out after writing the first file.
  • AudioFileClose -- and you're done!

Things to note: for local files, you have to run a method to escape spaces

That's about it!



来源:https://stackoverflow.com/questions/4506129/joining-two-caf-files-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!