Auggnet
Veteran developer
Profile
Posts: 225
Reg: Nov 20, 2012
USA
2,550
06/03/13 08:31 AM (12 years ago)

Add Sound Effects to a navigation button.

I would like to add sound fx to the button pushed. I dont want it so you have to add it into the cpanel, i want all buttons to make the same sound and i want it in the local code. No need to add json parsing and all of that.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
06/03/13 11:07 AM (12 years ago)
Go to BT_viewController.m from line 107 make the following changes //left button -(void)navLeftTap{ [BT_debugger showIt:self theMessage:@"navLeftTap"]; //child apps are handled different... favouritesplugin_appDelegate *appDelegate = (favouritesplugin_appDelegate *)[[UIApplication sharedApplication] delegate]; [appDelegate playSoundEffect:@"blow.mp3"];///<newline if([appDelegate.rootApp isChildApp]){ [BT_viewControllerManager closeChildApp]; }else{ //handle "left" transition [BT_viewControllerManager handleLeftButton:screenData]; } } //right button -(void)navRightTap{ yourApp_appDelegate *appDelegate = (yourApp_appDelegate *)[[UIApplication sharedApplication] delegate]; ///<newline [appDelegate playSoundEffect:@"blow.mp3"]; ///<newline [BT_debugger showIt:self theMessage:@"navRightTap"]; //handle "right" transition [BT_viewControllerManager handleRightButton:screenData]; } substitute "blow.mp3" to whatever your sound effect is called. Make sure you also add the name of the mp3 to the soundEffect array in the appDelegate -(void)loadSoundEffects{ //this runs in it's own thread NSAutoreleasePool *pool = [ [ NSAutoreleasePool alloc ] init ]; [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"loadSoundEffects SEE appDelegete.m, line 924 %@", @""]]; //fill an array of sound effect file names... self.soundEffectNames = [[NSMutableArray alloc] init]; [self.soundEffectNames addObject:@"yourSoundEffect.mp3"]; ///<NEW LINE [self.soundEffectNames addObject:@"blow.mp3"]; //setup audio session for sound effects... [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil]; [[AVAudioSession sharedInstance] setActive: YES error: nil]; You could have written your own audio script but may aswell use buzztouches code
 
Auggnet
Veteran developer
Profile
Posts: 225
Reg: Nov 20, 2012
USA
2,550
like
06/04/13 10:33 AM (12 years ago)
WOW Thankyou so much! I was getting a hang of the appdelagate methods this helped a lot! Thanks @Kittsy
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.