Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-23-2009, 10:15 PM   #1 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 12
Default Help with playing wav sound

Hello, I'm developing a utilitie for iPhones, and I want to make this app play a wav sound. I've created a SystemSound soundID*, and I've done everything that apple documentation tells me to do. Can somebody help me ? The main code is:

Code:
#import "ShakeAndBreakViewController.h"

@implementation ShakeAndBreakViewController

@synthesize imageView,brokenShow,fixed,broken,takePictureButton,imageShow,showButton;

#import <AudioToolbox/AudioToolbox.h>
- (void)viewDidLoad {
	if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
		takePictureButton.hidden = YES;
	}
	UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
	accel.delegate = self;
	accel.updateInterval = kUpdateInterval;
	
	NSString *path = [[NSBundle mainBundle] pathForResource:@"glass" ofType:@"wav"];
	AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
	
	self.fixed = [UIImage imageNamed:@"home.png"];
	self.broken = [UIImage imageNamed:@"vidro.png"];
	
	imageView.image = fixed;
	brokenShow.hidden = YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
	// Release anything that's not essential, such as cached data
}

- (void)dealloc {
	[showButton release];
	[imageView release];
	[imageShow release];
	[takePictureButton release];
	[brokenShow release];
	[fixed release];
	[broken release];
	[super dealloc];
}
#pragma mark -
- (IBAction)getCameraPicture:(id)sender {
	UIImagePickerController *picker = [[UIImagePickerController alloc] init];
	picker.delegate = self;
	picker.sourceType = (sender == takePictureButton) ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
	picker.allowsImageEditing = YES;
	[self presentModalViewController:picker animated:YES];
	[picker release];
	showButton.hidden = YES;	
}
- (IBAction)selectExistingPicture {
	if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
		UIImagePickerController *picker = [[UIImagePickerController alloc] init];
		picker.delegate = self;
		picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
		[self presentModalViewController:picker animated:YES];
		[picker release];
		showButton.hidden = YES;	
	}
	else {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil];
		[alert show];
		[alert release];
		showButton.hidden = YES;	
	}
}
#pragma mark  -
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
	imageView.image = image;
	[picker dismissModalViewControllerAnimated:YES];
	showButton.hidden = YES;
	
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
	
	[picker dismissModalViewControllerAnimated:YES];
}
- (void)accelerometer:(UIAccelerometer *)accelerometer
		didAccelerate:(UIAcceleration *)acceleration {
	if(! brokenScreenShowing) {
		if (acceleration.x > kAccelerationThreshold
			|| acceleration.y > kAccelerationThreshold
			|| acceleration.z > kAccelerationThreshold) {
			brokenShow.hidden = NO;
			AudioServicesPlaySystemSound (soundID);
			showButton.hidden = YES;
		}
	}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	imageView.image = fixed;
	brokenShow.hidden = YES;
	showButton.hidden = NO;
}

@end
OBS: I've already added the AudioToolbox.framework, and the sound file to the resources folder.
Thanks !

Last edited by Negativi; 04-23-2009 at 10:15 PM. Reason: Fixed the code
Negativi is offline   Reply With Quote
Old 04-23-2009, 11:17 PM   #2 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 12
Default

Help please !
Negativi is offline   Reply With Quote
Old 04-24-2009, 12:17 AM   #3 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 12
Default

Help !!
Negativi is offline   Reply With Quote
Old 01-29-2010, 05:44 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 1
Default Idea for you to try

Sorry for the delay but I have just started developing on the iPhone and have just stumbled upon the same issue. Have you tried adding the Frameworks in the groups and files section. Basically where all the folders and resources are, there is one named Frameworks, in there add an existing framework and add the Audio toolbox one.
Trevor_Newsome is offline   Reply With Quote
Old 01-29-2010, 08:25 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 172
Default

This is a simple code to play a wav file. Add AVFoundation and AudioToolbox framework to your project.

Code:
	NSString *pathForSilentFile = [[NSBundle mainBundle] pathForResource:@"noSound" ofType:@"wav"];
	NSURL *soundFile = [[NSURL alloc] initFileURLWithPath:pathForSilentFile];
	AVAudioPlayer *sPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:NULL];
	[soundFile release];
	[sPlayer prepareToPlay];
	
	[sPlayer play];
note that i have a noSound.wav file in my project.
raziiq is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, play, sound, wav

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 356
21 members and 335 guests
ADY, Dani77, Duncan C, e2applets, HemiMG, Herbie, JasonR, keeshux, linkmx, macquitzon216, mer10, Monstertaco, prchn4christ, Promo Dispenser, Robiwan, sebasx, sly24, Touchmint, twerner, zulfishah
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,881
Threads: 89,228
Posts: 380,760
Top Poster: BrianSlick (7,129)
Welcome to our newest member, macquitzon216
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:36 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0