iphoneのNSSound
-
23-08-2019 - |
質問
私は、iPhone上でサウンドを再生する方法をしばらく見てきた、と私はそれがの線に沿って何かだと思います:
[[NSSound soundNamed:@"cat.mp3"] play];
しかしNSSoundは...のAppKitに任意の提案ですか?私はこれには本当に簡単な答えがあると知っているが、今日の私の検索は、任意の結果をレンダリングされていません...
解決
それが唯一のファームウェア2.2用ですが、
新しいAVFoundationクラスは、iPhone上でサウンドを再生するための最も簡単な方法です。
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer play];
あなたはそれを使用するクラスで、このインポートが必要になります:
#import <AVFoundation/AVAudioPlayer.h>
他のヒント
オーディオ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);
私はAudioServicesPlaySystemSound
で動作するようにMP3ファイルをもらっていません。しかし、それは完全にAIFファイルを果たしています。
所属していません StackOverflow