AVFoundationを用いた音声ファイルの再生方法
今回はSEならしたいだけなのでAVFoundationを使用してみた。
(参考記事 http://freeek.jp/blog/iphone/37/)
1. フレームワークにAVFoundationを追加する。
2. ヘッダ追加
#import <AVFoundation/AVFoundation.h>
3. 再生準備
AVAudioPlayer *player; NSString *path = [[NSBundle mainBundle] pathForResource:@"soundfilename" ofType:@"wav"]; NSURL *url = [NSURL fileURLWithPath:path]; if(url){ NSError *err = nil; player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err]; }
4. 再生
[player play];