iPhoneでサウンドを再生する方法をしばらく探していましたが、次のようなものだと思います。
[[NSSound soundNamed:@"cat.mp3"] play];
しかし、NSSound は AppKit にあります...何か提案はありますか? これには本当に簡単な答えがあることは知っていますが、今日、私の検索では結果が得られません...
iPhoneでサウンドを再生する方法をしばらく探していましたが、次のようなものだと思います。
[[NSSound soundNamed:@"cat.mp3"] play];
しかし、NSSound は AppKit にあります...何か提案はありますか? これには本当に簡単な答えがあることは知っていますが、今日、私の検索では結果が得られません...
新しい AVFoundation クラスは、iPhone でサウンドを再生する最も簡単な方法ですが、ファームウェア 2.2 専用です。
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer play];
それを使用するクラスでこのインポートが必要なだけです:
#import <AVFoundation/AVAudioPlayer.h>
Audio Toolbox システム サウンドは、短い非同期再生に最適です。
// Initialize
CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle ();
// Init each sound
CFURLRef tapURL;
SystemSoundID tapSound;
tapURL = CFBundleCopyResourceURL(mainBundle, CFSTR("tap"), CFSTR("aif"), NULL);
AudioServicesCreateSystemSoundID(tapURL, &tapSound);
// Play the sound async
AudioServicesPlaySystemSound(tapSound);
で動作する MP3 を取得していませんAudioServicesPlaySystemSound
。しかし、AIF ファイルは完全に再生されます。