문제

나는 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>

다른 팁

오디오 도구 상자 시스템 사운드는 짧은 비동기 재생에 적합합니다.

// 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 파일을 완벽하게 재생합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top