標籤:
AVAudioPlayer是AVFoundation架構中播放音訊一個類,此次使用的比較簡單,今後涉及音頻方面的用法,再增加總結
每個AVAudioPlayer對應一個音頻,主要建立方法為
- (instancetype)initWithContentsOfURL:(NSURL *)url error:(NSError **)outError;- (instancetype)initWithData:(NSData *)data error:(NSError **)outError;
推薦格式:
- 對於非壓縮音頻,caf格式(16-bit, little endian,linear PCM)
-對於壓縮音頻,且一次播放一個音頻,使用caf,或者m4a格式
- 若同時播放多個聲音,考慮降低記憶體,可使用IMA4壓縮,,使用caf格式
可使用mac afconvert 命令轉換格式
1. cd 到需要轉換的檔案目錄下
2. 命令格式為 afconvert [option...] input_file [output_file],option的形式是
3. 比如afconvert -f caff -d LEI16 {INPUT} {OUTPUT} 轉換為use 16-bit, little endian, linear PCM caf檔案
AVAudioPlayer主要的播放方法:
@property NSTimeInterval currentTime;- (BOOL)play; /* sound is played asynchronously. */- (BOOL)playAtTime:(NSTimeInterval)time NS_AVAILABLE(10_7, 4_0); /* play a sound some time in the future. time is an absolute time based on and greater than deviceCurrentTime. */- (void)pause; /* pauses playback, but remains ready to play. */- (void)stop; /* stops playback. no longer ready to play. */
iOS開發總結(A0)- AVAudioPlayer