尝试在应用程序的背景下实现一个简单的声音效果。代码基于以下答案:Best way to play simple sound effect in iOS。
- (void) viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:@"poke_sound" ofType:@"mp3"];
NSURL *pathURL = [NSURL fileURLWithPath : path];
SystemSoundID audioEffect;
AudioServicesCreateSystemSoundID((CFURLRef) CFBridgingRetain(pathURL), &audioEffect);
AudioServicesPlaySystemSound(audioEffect);
}当我在模拟器中运行应用程序时,噪音不会播放。谢谢你的帮助!
注意:--我使用的是xcode 6测试版,那么谁知道那里会弹出哪些bug呢?
发布于 2014-06-09 08:21:04
您不能使用音频服务来播放MP3。你只能玩咖啡馆,AIF,或WAV。但是,例如,您可以使用MP3来玩AVAudioPlayer。查看本文以获得更多信息:http://www.raywenderlich.com/69369/audio-tutorial-ios-playing-audio-programatically-2014-edition
https://stackoverflow.com/questions/24113908
复制相似问题