//
//  helloaudioViewController.m
//  helloaudio
//
//  Created by Bess Ho on 8/4/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "helloaudioViewController.h"

@implementation helloaudioViewController

@synthesize audioFileURLRef;
@synthesize audioFileObject;

- (void)dealloc {
    AudioServicesDisposeSystemSoundID (audioFileObject);
    CFRelease (audioFileURLRef);
    [super dealloc];
}

- (void)viewDidLoad {
	
    [super viewDidLoad];
	
	// Select TableView as background color
	self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
}

- (IBAction) playSystemButton: (id) sender {
	// Create the URL for audio file
	NSURL *audioURL   = [[NSBundle mainBundle] URLForResource: @"tap" withExtension: @"aif"];
	
	// Store URL as CFURLRef instance
	self.audioFileURLRef = (CFURLRef) [audioURL retain];
	
	// Create a system sound object
	AudioServicesCreateSystemSoundID(audioFileURLRef, &audioFileObject);
	
	// Play system audio
	AudioServicesPlaySystemSound (audioFileObject);
	
	// Invoke Vibration
	//AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
}

- (IBAction) playAlertButton: (id) sender{
	NSURL *audioURL = [[NSBundle mainBundle] URLForResource: @"tap" withExtension: @"aif"];
	self.audioFileURLRef = (CFURLRef) [audioURL retain];
	AudioServicesCreateSystemSoundID(audioFileURLRef, &audioFileObject);
	AudioServicesPlayAlertSound (audioFileObject); // Play alert audio
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

/*
 // The designated initializer. Override to perform setup that is required before the view is loaded.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
 // Custom initialization
 }
 return self;
 }
 */

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView {
 }
 */

/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

@end

