6

I'm in the early stages of developing my first iPad application, and for simplicity I have so far been using AudioServicesPlaySystemSound and the associated functions to play sounds. My code is based the SoundEffect class from Apple's Metronome example.

The specific symptom is that I can hear the sounds in the simulator but not on the device, though I have verified that I can hear sounds in other applications on the device. AudioServicesCreateSystemSoundID is returning valid sound identifiers, so it isn't anything as simple as the name of the sound file having different case, i.e. "sound.mp3" vs. "Sound.mp3".

I recognize that I may need to switch to a different library such as OpenAL for unrelated reasons, but I would like to know what is going on here. Does anyone have any suggestions? Is there a function I can call to get an OSStatus value or something?

* BUMP -- I've been working on other projects for the past few weeks but I'm back on this now and I'd really appreciate an answer. Thanks.

Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92
Amagrammer
  • 6,385
  • 3
  • 28
  • 30

2 Answers2

5

I came across this question via a Google search. My problem is exactly as stated in the title of this question: "AudioServicesPlaySystemSound not working on iPad device". However, the description of the issue is different.

Simply put, after upgrading my iPad to iOS 4.3, AudioServicesPlaySystemSound stopped working.

I finally found the solution to my version of the issue, so hopefully this helps someone else.

Go to the Settings app on the iPad and choose General. Tap Sounds. Make sure "Change with Buttons" is set to ON. This will fix the issue.

Jeremy Fuller
  • 3,391
  • 1
  • 32
  • 27
  • I'm running iOS 4.3.1 and I don't have a "Change with Buttons" option in General->Sounds. – iPadDeveloper2011 Apr 24 '11 at 14:53
  • It's been a while since this happened, but I think it may only apply to iPad 2. They may have also changed the behavior in 4.3.1 -- this response applies to 4.3. – Jeremy Fuller Apr 24 '11 at 20:58
  • I used iTunes to change my .m4v sound to a .aif, which is a "supported" encoding. That worked. – iPadDeveloper2011 Apr 25 '11 at 05:44
  • 1
    I'm all the way up to iOS 9 and this kinda solved it for me. I had to make sure that the volume for "ringers and alerts" was all the way up. My sound effects were muted because I had the ringer volume down kinda low and the volume for AudioServicesPlaySystemSound is controlled by that setting. – TMc Mar 20 '16 at 00:18
2

I don't think you can play an mp3 file on the device using AudioServicesPlaySystemSound. Take a look at the documentation for supported file types. I'm not sure why they play correctly in the simulator, but I had the same issue. Try using AVAudioPlayer instead:

NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource: @"sound" withExtension: @"mp3"] error:&error];
if (error)  {
    NSLog(@"Error creating audio player: %@", [error userInfo]);
} else {
    [audioPlayer play];
}

[audioPlayer release];
Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92