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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 06-11-2010, 02:03 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 35
SynSoft is on a distinguished road
Default Shake To Play Sound

I'm writing a small app that when you shake the phone it plays a sound, and how hard you shake it determines how long the sound will play for. I've set up 3 Konstants (sorry had to small programming joke) of the accelerometer thresholds kAccelerationThreshold, kAccelerationThreshold2, and kAccelerationThreshold3. Then wrote the methods for them.

Code:
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
	if(acceleration.x > kAccelerationThreshold || acceleration.y > kAccelerationThreshold || acceleration.z > kAccelerationThreshold){
		NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
		AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
		theAudio.delegate = self;
		[theAudio play];
	}if(acceleration.x > kAccelerationThreshold2 || acceleration.y > kAccelerationThreshold2 || acceleration.z > kAccelerationThreshold2){
		NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
		AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
		theAudio.numberOfLoops = 3;
		theAudio.delegate = self;
		[theAudio play];
	}if(acceleration.x > kAccelerationThreshold3 || acceleration.y> kAccelerationThreshold3 || acceleration.z > kAccelerationThreshold3){
		NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
		AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
		theAudio.numberOfLoops = 5;
		theAudio.delegate = self;
		[theAudio play];
	}
}

I havn't paid for the developer license yet, I want to have a full fledged app before I do that, but I've built it and there are no errors everything builds and compiles fine, I just want to know if I'm on the right track as I've just pieced all this info I've found together. If there is an easier way to do this I'm open to ideas! but I just really want to make sure this works as I have no way of testing it.

thanks in advance
SynSoft is offline   Reply With Quote
Old 06-12-2010, 10:44 PM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 35
SynSoft is on a distinguished road
Default

I guess no news is good news?
SynSoft is offline   Reply With Quote
Reply

Bookmarks

Tags
accelerometer, avaudioplayer, looping, shake, sound

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: 333
11 members and 322 guests
Absentia, Domele, fiftysixty, givensur, heshiming, iGamesDev, linkmx, michaelhansen, PixelInteractive, raihan.zbr, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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