user963574
user963574

Reputation:

AudioServicesCreateSystemSoundID not playing mp3 files

Can anyone answer how to play mp3 files using AudioServicesCreateSystemSoundID()? I tried but not working.

I have used the following code snippet for playing mp3

NSURL *soundURL   = [[NSBundle mainBundle] URLForResource:fileName withExtension:extension];

soundFileURLRef = (CFURLRef) [soundURL retain];

// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID ( soundFileURLRef,&soundFileObject);

Upvotes: 1

Views: 1178

Answers (1)

Wil
Wil

Reputation: 380

I had the same problem using this example. Maybe your sound sample is to big/long.

NSString *path = [[NSBundle mainBundle] pathForResource:@"tap" ofType:@"aif"];

NSURL *url = [NSURL fileURLWithPath:path];AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &mBeep);

AudioServicesPlaySystemSound(mBeep);

It was not working because the audio file was to long. I tried with the sound from the apple example http://developer.apple.com/library/ios/#samplecode/SysSound/Introduction/Intro.html "tap.aif" and it worked fine.

Upvotes: 1

Related Questions