Posted By

espinallab on 04/29/10


Tagged

Objective-c AVAudioPlayer


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

cplusplus
avanadra
umang_nine
rvachere
Tintenklecks


AVAudioPlayer


 / Published in: Objective C
 

URL: http://github.com/msanders/Simon-Classic/blob/f8a2f67a9de6eca5d6073e6c2f19fb1e20e8548d/Source/Categories/AVAudioPlayer%2BSoundNamed.m

  1. //
  2. // AVAudioPlayer+SoundNamed.m
  3. // Simon Classic
  4. //
  5. // Created by Michael on 2/9/10.
  6. // Copyright 2010 Michael Sanders.
  7. //
  8.  
  9. #import "AVAudioPlayer+SoundNamed.h"
  10.  
  11. @implementation AVAudioPlayer (SoundNamed)
  12.  
  13. - (id)initWithSoundNamed:(NSString *)name
  14. ofType:(NSString *)type
  15. error:(NSError **)error
  16. {
  17. NSString *soundPath = [[NSBundle mainBundle] pathForResource:name
  18. ofType:type];
  19. if (soundPath == nil) return nil;
  20.  
  21. NSURL *soundURL = [NSURL fileURLWithPath:soundPath isDirectory:NO];
  22. if (soundURL == nil) return nil;
  23.  
  24. return [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:error];
  25. }
  26.  
  27. @end

Report this snippet  

You need to login to post a comment.