ATMSoundFX.m 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * ATMSoundFX.m
  3. * ATMHud
  4. *
  5. * Created by Marcel Müller on 2011-03-01.
  6. * Copyright (c) 2010-2011, Marcel Müller (atomcraft)
  7. * All rights reserved.
  8. *
  9. * https://github.com/atomton/ATMHud
  10. */
  11. #import "ATMSoundFX.h"
  12. @implementation ATMSoundFX
  13. + (id)soundEffectWithContentsOfFile:(NSString *)aPath {
  14. if (aPath) {
  15. return [[ATMSoundFX alloc] initWithContentsOfFile:aPath];
  16. }
  17. return nil;
  18. }
  19. - (id)initWithContentsOfFile:(NSString *)path {
  20. self = [super init];
  21. if (self != nil) {
  22. NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO];
  23. if (aFileURL != nil) {
  24. SystemSoundID aSoundID;
  25. OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)aFileURL, &aSoundID);
  26. if (error == kAudioServicesNoError) {
  27. _soundID = aSoundID;
  28. } else {
  29. self = nil;
  30. }
  31. } else {
  32. self = nil;
  33. }
  34. }
  35. return self;
  36. }
  37. -(void)dealloc {
  38. AudioServicesDisposeSystemSoundID(_soundID);
  39. // [super dealloc];
  40. }
  41. -(void)play {
  42. AudioServicesPlaySystemSound(_soundID);
  43. }
  44. @end