Incompatible pointer to integer conversion passing 'SystemSoundID to parameter of type 'SystemSoundID'

StackOverflow https://stackoverflow.com/questions/22927016

  •  29-06-2023
  •  | 
  •  

Question

I don't understand AudioToolbox Framework... I have this line of code:

-(IBAction)PlaySound1:(id)sender{

AudioServicesPlaySystemSound(PlaySoundID1);

}

But xcode give me this error:

Incompatible pointer to integer conversion passing 'SystemSoundID to parameter of type 'SystemSoundID'

Xcode suggest me to do this instead:

-(IBAction)PlaySound1:(id)sender{

AudioServicesPlaySystemSound(*(PlaySoundID1));

}

But if i do that, the sound doesn't play! Plus i've seen many youtube tutorials where people didn't even get an error... Is there a way to disable a certain warning in xcode or is there a way to fix this issue?

EDIT: i also get the same error on this line on code:

AudioServicesCreateSystemSoundID((__bridge CFURLRef)SoundURL1, &PlaySoundID1);

Xcode suggest me to take off the "&" infront of my system sound id but if i do so, the sound won't play! The only time the sound play is if i contradict xcode (i normally wouldn't mind but since i'm having over a 100 sounds, the amount of errors is ridiculous!)

enter image description here

Was it helpful?

Solution

Based on the error you are most likely defining PlaySoundID1 incorrectly.

You probably have something like:

SystemSoundID *PlaySoundID1;

but what you need is:

SystemSoundID PlaySoundID1; // no asterisk

Your call to AudioServicesCreateSystemSoundID should be something like:

SystemSoundID usedSoundID;
OSStatus status = AudioServicesCreateSystemSoundID((__bridge CFURLRef)SoundURL1, &usedSoundID);
// check the status and look at usedSoundID as needed

The 2nd parameter is an "out" value so you should not be passing in your PlaySoundID value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top