问题
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