//
//  PlaySound.m
//
//  Created by 今井 彰彦 on 2011/04/09.
//  Copyright 2011 AIG-Soft. All rights reserved.
//
//  フレームワークにAudioToolbox.framaworkの追加が必要

#import "PlaySound.h"

@implementation PlaySound

-(id)initWithSound:(NSString *)fname ext:(NSString *)ext
// 音声データの読み込み
{
	nslog(@"音声データの読み込み");
	// CFStringはNSStringと同一なので、型キャストだけでいい
	soundURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),(__bridge CFStringRef)fname,(__bridge CFStringRef)ext,NULL);
	if (soundURL==NULL) {
		nslog(@"ファイル付が見つかりません:%@.%@",fname,ext);
		return(nil);
	}
	AudioServicesCreateSystemSoundID (soundURL, &soundID);
	CFRelease (soundURL);
	//
	return (self);
}

-(void)play
{
	nslog(@"音再生:%lu",(ULong)soundID);
	AudioServicesPlaySystemSound (soundID);
}

-(void)dealloc
{
	AudioServicesDisposeSystemSoundID (soundID);
}

@end
