Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 11    Views: 66

maverick96
Lost but trying
Profile
Posts: 174
Reg: Jan 22, 2014
Orlando
3,390
03/22/15 12:20 PM (9 years ago)

Adding audiocontroller

If a project doesn't have an audiocontroller.h/.m, can it be imported or do I need to create them in Xcode?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/22/15 03:58 PM (9 years ago)
"Usually" BT_audio.m is enough for most purposes; it's included in the 'core' files. It allows you to play audio files throughout your buzztouch project. What were you planning to do? Cheers! -- Smug
 
maverick96
Lost but trying
Profile
Posts: 174
Reg: Jan 22, 2014
Orlando
3,390
like
03/22/15 04:23 PM (9 years ago)
I know how to have music play in the background over the whole app but what I'm trying to achieve is having the main screen have one music file that plays only on that screen & the quiz have another music file that plays only on that screen. I've been reading and looking at tutorials (ex. RAY WENDERLICH) and can't figure out how to implement this. Any help is appreciated.
 
aussiedra
Code is Art
Profile
Posts: 431
Reg: Dec 25, 2010
Brisbane, Austr...
8,260
like
03/22/15 07:13 PM (9 years ago)
#import <AVFoundation/AVFoundation.h> should do the trick
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/23/15 02:39 AM (9 years ago)
Well... a little work, but it's all good in the end. First, find and locate "playSoundEffect". It's in your appDelegate file, around line 786-ish. Copy that method (play sound effect) and paste it... Then change it to look like this: //stopSoundEffect... -(void)stopSoundEffect { [BT_debugger showIt:self message:[NSString stringWithFormat:@"stopSoundEffect %@", @""]]; for(int i = 0; i < [self.soundEffectPlayers count]; i++){ AVAudioPlayer *tmpPlayer = (AVAudioPlayer *)[self.soundEffectPlayers objectAtIndex:i]; if(tmpPlayer){ [tmpPlayer stop]; } } } There. Now you have matching methods; one for start, and one for stop. For each audio file, be sure to add it to your array of soundeffect names. This is done in BT_loadConfigDataViewController.m, around line 403 or so... add your audio files the same way. [appDelegate.soundEffectNames addObject:@"yourfilename.mp3"]; Now, in each plugin you want to use this in, just put '[self stopSoundEffect];' somewhere in viewDidLoad and put '[self startSoundEffect:@"yourfilename.mp3"]; in viewWillAppear of the 'target' plugin. So basically 1) Add your music to the bundle. 2) Add your filenames to the array of soundeffects. 3) At the beginning of a plugin load, 'stop' the music. 4) At the end of a plugin load 'start' the new music. Hope this helps. Cheers! -- Smug
 
maverick96
Lost but trying
Profile
Posts: 174
Reg: Jan 22, 2014
Orlando
3,390
like
03/23/15 05:20 AM (9 years ago)
Thanks so much! Getting the following errors though: [self startSoundEffect:@"yourfilename.mp3"]; brings up: Expected identifier or '(' Use of undeclared identifier 'self' [self stopSoundEffect]; brings up: No visible @interface for 'BT_screen_quiz' declares the selector 'stopSoundEffect'
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/23/15 07:11 AM (9 years ago)
Oh... you want something that *works*. Why didn't you say so. ;) Instead of 'self', try '[appDelegate startSoundEffect:@"yourfilename.mp3"]; you may need to do the same for the stop method as well. Also, you 'might' need to declare appDelegate if it goes red on you. That's fairly common, and should be an example somewhere in your plugin code. It'll look sort of like this: BT_appDelegate *appDelegate = (BT_appDelegate *)[[UIApplication sharedApplication] delegate]; Let us know how it goes... Cheers! -- Smug
 
maverick96
Lost but trying
Profile
Posts: 174
Reg: Jan 22, 2014
Orlando
3,390
like
03/23/15 07:44 AM (9 years ago)
Haha. I would love for it to work! ;) Getting same errors as before but now with "appDelegate" instead of "self" BT_appDelegate *appDelegate = (BT_appDelegate *)[[UIApplication sharedApplication] delegate]; is present in the project too.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/23/15 07:55 AM (9 years ago)
Oh, for that 'visible interface selector' issue, you'll need to add that method to the appDelegate.h file as well. It'll look something like this: -(void)playSoundEffect:(NSString *)theFileName; -(void)stopSoundEffect; 'playSound Effect' will already be there. Just 'add' stopSoundEffect when you find it. Cheers! -- Smug
 
maverick96
Lost but trying
Profile
Posts: 174
Reg: Jan 22, 2014
Orlando
3,390
like
03/23/15 08:08 AM (9 years ago)
Ok. Added '-(void)stopSoundEffect;' Still getting this. [appDelegate startSoundEffect:@"Dawn.mp3"]; brings up: Expected identifier or '(' Use of undeclared identifier 'appDelegate' [appDelegate stopSoundEffect]; brings up Use of undeclared identifier 'appDelegate'
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/23/15 08:14 AM (9 years ago)
Well, that appDelegate needs to be called in the method just before the '[appDelegate stopSoundEffect];'. and it proabably won't be 'BT_appDelegate'... it changes the name to whatever your app name is. so, if you named your app "JoesGarage" it should say 'JoesGarage_appDelegate' instead of 'BT_appDelegate'. Do a search in any odd plugin for 'appDelegate' and you'll soon see what I mean. You'll get there. persistance and patience are key elements in this wrestling match. Cheers! -- Smug
 
maverick96
Lost but trying
Profile
Posts: 174
Reg: Jan 22, 2014
Orlando
3,390
like
03/23/15 08:47 AM (9 years ago)
Everything I have found references this in my project: namethathorror_appDelegate *appDelegate = (namethathorror_appDelegate *)[[UIApplication sharedApplication] delegate]; Now in my namethathorror_appDelegate.h this is below '#import <AVFoundation/AVFoundation.h>' in the project: @interface namethathorror_appDelegate:UIResponder <UIApplicationDelegate,AVAudioPlayerDelegate>{ AVAudioPlayer *appDelegate; } Is this correct or could it be causing an issue?
 

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.