Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couldn't play system sound after switching to iOS 5

This is how I played a beep sound effect in iOS 4:

SystemSoundId beepOnSoundId;

CFURLRef soundUrl = CFBundleCopyResourceURL(
    CFBundleGetMainBundle(), 
    CFSTR("beep"), 
    CFSTR("wav"), 
    NULL
);

// soundUrl logged:
// file://localhost/var/mobile/Applications/ ... beep.wav

AudioServicesCreateSystemSoundID(soundUrl, &beepOnSoundId);

// beepOnSoundId logged: 4097

AudioServicesPlaySystemSound(beepOnSoundId);

It stopped working, when I upgraded my device to iOS 5. I hear nothing. I logged out all the variables and none were nil or 0.

How has the API changed in iOS 5 that breaks my sound playing code?

Update

The problem may be because I have an AVCaptureSession running while I play the sound. iOS 5 somehow doesn't let you do this anymore. I need to play a beep sound while I am recording something from the camera.

like image 963
JoJo Avatar asked Oct 22 '11 01:10

JoJo


2 Answers

This bug report could be related to your question, if you have an AVCaptureSession running.

Under iOS 5, when using an AudioServicesPlaySystemSound call, it will not work when there is an active AVCaptureSession with an audio device active.

like image 62
jbat100 Avatar answered Oct 21 '22 03:10

jbat100


One problem could be that in ios 5 when you call AudioServicesPlaySystemSound, it stop working if there is an active AVCaptureSession with an audio device active.

Also check the names of imports in your files, make sure the audiotoolbox import is in all your viewcontrollers. I also went to a guide and got this for you :) I'll leave the website's name at the bottom

Step 1: Import the AudioToolbox Framework Begin by importing the Audio Toolbox framework into your application in order to make the System Sound Services available to your code. To do so, select the “PhoneAppSkin” project in the Project Navigator pane in Xcode, then select “PhoneAppSkin” under “TARGETS”, and finally select the “Build Phases” tab. After doing so, your screen should look something like this:

enter image description here

Next, click the “Link Binary With Libraries” drop down, and click the “+” symbol to add a new framework to our project’s linking phase.

enter image description here

Finally, find the “AudioToolbox” framework in the popup window, and then click “Add”.

enter image description here

Next, open up the PhoneViewController.h file and add the line necessary to actually import the Audio Toolbox framework into your class:

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>

The Audio Toolbox functions should now work

Website I got the images from: http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_playing-systemsoundid/

like image 45
Gabriel Avatar answered Oct 21 '22 05:10

Gabriel