3

I am working on creating a very simple app. 2 buttons, both play sound. Each clip lasts 1 second and responds to "TouchUpInside". They are .caf files that I converted in iTunes.

Here is my code, once again, it works in the simulator but not on the device:

enter code here- (void)viewDidLoad {

    NSLog(@"InView did load");

AudioServicesCreateSystemSoundID ((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"bigaif" ofType:@"caf"]], &systemSoundID);


    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] 
                                                                   pathForResource: @"smallwav" ofType:@"wav"]],                                                            
                                                                    &systemSoundIDTwo);

}

-(IBAction) playSound:(id) sender {
AudioServicesPlaySystemSound(systemSoundID);
}

-(IBAction) playSoundTwo:(id) sender {
AudioServicesPlaySystemSound(systemSoundIDTwo);

}

JoshD
  • 156
  • 2
  • 13
  • Do not have any problems with filenames? Faced with the fact that the mac was set to casemapping and due to a typo in the file name was the same situation – aknew Sep 14 '11 at 08:09
  • Well, I figured it out by myself. I wanted to post the solution so others don't make this mistake. When using "SystemSound", make sure you have your system sounds turned up in your settings. – JoshD Sep 14 '11 at 12:57

4 Answers4

15

After looking for errors in my code for the past 30 min I found that the mute button on the side of iPad was on. Check that before trying some fancy solution.

30 min well spent...

Groot
  • 13,943
  • 6
  • 61
  • 72
4

I found my answer. I was using SystemSound and what do you know, I had my system sounds muted in my device settings.

JoshD
  • 156
  • 2
  • 13
  • This setting can be changed also with the mute button on the side of the device next to volume buttons. – Radek Aug 23 '12 at 10:46
  • Somewhat similar problem. Fixed by going into settings and turning up the volume on Sounds->Ringer and Alerts – northernman Dec 15 '12 at 01:48
3

I had same issue. I didn't add a link reference to the AudioToolbox.framework but it still worked on simulator. I added it and it played in the foreground of my app on the device.

Then I wanted it to play the sound in the background. In info.plist "Required background modes" add the key "plays audio". That got it working the background.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
0

This happened to me as well. Sounds were playing just fine in the simulator, but not on the device. I tried to play the sounds multiple different ways. I used both SystemSound and AVAudioPlayer with the same results. I even downloaded the code from a Mobile Orchard tutorial, and had the same result. Code example worked fine in simulator, but wouldn't play on the device.

After 2 hours of this, I double-tapped the home button on the iPad, scrolled to the left to the sound controls, and then tapped the speaker icon on the left. That placed a slash through the speaker icon to indicate that system volume was muted. I then tapped again, the slash went away, and I was then able to play sounds through the device.

So basically, I had to toggle through the muted state of the device using this method and that reset something on the iPad to where I could hear the sounds.

Note that this was on iOS6.

TheJerkMan24
  • 272
  • 4
  • 9