1

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);
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Can you show what have you tried? – Darin Dimitrov Sep 25 '11 at 12:13
  • NSURL *soundURL = [[NSBundle mainBundle] URLForResource:fileName withExtension:extension]; //filename and extension are given while calling the function. soundFileURLRef = (CFURLRef) [soundURL retain]; AudioServicesCreateSystemSoundID ( soundFileURLRef,&soundFileObject); –  Sep 25 '11 at 12:16
  • Please don't post code snippets in the comments section as they cannot be properly formatted and are completely unreadable. Go ahead and update your original question. – Darin Dimitrov Sep 25 '11 at 12:17

1 Answers1

1

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Wil
  • 351
  • 3
  • 9