问题
I realize this question has been asked before, but I haven't seen an answer that works for my needs. Basically I have full length songs in .caf format but I need to be able to upload/download them from a server. Is it viable to do compression (to something like .mp3 or .wav) on the iPhone and then send them to the server? How would I go about doing this?
回答1:
Refer to AudioConverterServices.. the function that does the magic trick is AudioConverterNew.. however note that you can only convert from a variable bit rate (VBR) file to PCM (lossless format), and from PCM to VBR.. so in your case you will have to convert the file from .caf
to PCM
, then from PCM
to .mp3
or whatever format you want.
For a comprehensive example that illustrates all the steps necessary in doing an audio conversion.. download the free sample code for the book Learning Core Audio. You want chapter 6 sample code for audio conversion. (anyone who is serious about core audio should buy that book).
回答2:
Mp3 encoding on an iPhone requires finding and using a non-Apple-provided library. There is nothing built-in that will do mp3 encoding, only AAC.
回答3:
Using Lame, you can do this. Ther is no default function for this. It will also reduce the file size also. For 60 second audio file .caf will take approx 5mb - 10mb but after converting to .mp3 it will take 0.6mb to 0.7mb. Set 'Enable Bitcode' to 'NO' in build setting for new xocde, otherwise you will get error. For sample code use this LINK.
来源:https://stackoverflow.com/questions/15607889/convert-caf-to-mp3-on-iphone