Posted By

habib123 on 01/31/10


Tagged

audio sound iphone


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

davidsi
umang_nine
avanadra
bobbym245
Tintenklecks


Play sound


 / Published in: Objective C
 

  1. //To load sound file.
  2. +(void) playSound:(NSString *)fileName {
  3. NSString *path = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],fileName];
  4.  
  5. //declare a system sound id
  6. SystemSoundID soundID;
  7.  
  8. //Get a URL for the sound file
  9. NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
  10.  
  11. //Use audio sevices to create the sound
  12. AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
  13.  
  14. //Use audio services to play the sound
  15. AudioServicesPlaySystemSound(soundID);
  16. }

Report this snippet  

You need to login to post a comment.