alex
alex

Reputation: 879

How can I plan an alert sound?

I try to play a alertSound, but I have 4 error, this is my function:

#import "AudioToolbox/AudioServices.h"
+(void)jouerSon:(NSString *)fichierSon:(NSString *) extensionFichier
{

NSString* soundPath = [[NSBundle mainBundle] pathForResource:fichierSon ofType:extensionFichier];
CFURLRef baseURL = (CFURLRef) [NSURL fileURLWithPath:soundPath];
SystemSoundID mysound;

AudioServicesCreateSystemSoundID(baseURL,&mysound);
AudioServicesPropertyID flag = 0;
AudioServicesSetProperty(kAudioServicesPropertyIsUISound,sizeof(SystemSoundID), &mysound, sizeof(AudioServicesPropertyID), &flag);

AudioServicesPlayAlertSound(mysound);

//AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

AudioServicesDisposeSystemSoundID(mysound);
}

and this is the log error:

Ld build/Debug-iphonesimulator/ProjetMission.app/ProjetMission normal i386
cd /Users/sylvainlaroche/iPhone/ProjetMission
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk -L/Users/sylvainlaroche/iPhone/ProjetMission/build/Debug-iphonesimulator -F/Users/sylvainlaroche/iPhone/ProjetMission/build/Debug-iphonesimulator -filelist /Users/sylvainlaroche/iPhone/ProjetMission/build/ProjetMission.build/Debug-iphonesimulator/ProjetMission.build/Objects-normal/i386/ProjetMission.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -o /Users/sylvainlaroche/iPhone/ProjetMission/build/Debug-iphonesimulator/ProjetMission.app/ProjetMission

Undefined symbols:
  "_AudioServicesDisposeSystemSoundID", referenced from:
      +[FonctionUtile jouerSon::] in FonctionUtile.o
  "_AudioServicesPlayAlertSound", referenced from:
      +[FonctionUtile jouerSon::] in FonctionUtile.o
  "_AudioServicesSetProperty", referenced from:
      +[FonctionUtile jouerSon::] in FonctionUtile.o
  "_AudioServicesCreateSystemSoundID", referenced from:
      +[FonctionUtile jouerSon::] in FonctionUtile.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Upvotes: 3

Views: 2097

Answers (1)

user467105
user467105

Reputation:

You need to add the AudioToolbox framework to the project.
The import alone is not enough.

Upvotes: 5

Related Questions