123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /*
- * ATMSoundFX.m
- * ATMHud
- *
- * Created by Marcel Müller on 2011-03-01.
- * Copyright (c) 2010-2011, Marcel Müller (atomcraft)
- * All rights reserved.
- *
- * https://github.com/atomton/ATMHud
- */
- #import "ATMSoundFX.h"
- @implementation ATMSoundFX
- + (id)soundEffectWithContentsOfFile:(NSString *)aPath {
- if (aPath) {
- return [[ATMSoundFX alloc] initWithContentsOfFile:aPath];
- }
- return nil;
- }
- - (id)initWithContentsOfFile:(NSString *)path {
- self = [super init];
-
- if (self != nil) {
- NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO];
-
- if (aFileURL != nil) {
- SystemSoundID aSoundID;
- OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)aFileURL, &aSoundID);
-
- if (error == kAudioServicesNoError) {
- _soundID = aSoundID;
- } else {
- self = nil;
- }
- } else {
- self = nil;
- }
- }
- return self;
- }
- -(void)dealloc {
- AudioServicesDisposeSystemSoundID(_soundID);
- // [super dealloc];
- }
- -(void)play {
- AudioServicesPlaySystemSound(_soundID);
- }
- @end
|