【问题标题】:Trouble playing simple sound effect in iOS app在 iOS 应用中无法播放简单的音效
【发布时间】:2014-06-09 16:21:04
【问题描述】:

尝试实现一个简单的音效在应用后台播放。代码基于此处的答案: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 beta,所以谁知道那里会弹出什么错误

【问题讨论】:

    标签: ios objective-c audio


    【解决方案1】:

    您无法使用音频服务播放 MP3。您只能播放 CAF、AIF 或 WAV。但是您可以使用AVAudioPlayer 播放 MP3,例如。查看这篇文章了解更多信息:http://www.raywenderlich.com/69369/audio-tutorial-ios-playing-audio-programatically-2014-edition

    【讨论】:

      猜你喜欢
      • 2012-04-05
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多