iOS開發總結(A0)- AVAudioPlayer

來源:互聯網
上載者:User

標籤:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.