Discussion Forums  >  Audio, Video, Playing, Recording

Replies: 18    Views: 125

BuzzingSteve
Aspiring developer
Profile
Posts: 526
Reg: Jun 24, 2011
Vancouver, Cana...
11,660
05/08/13 12:49 PM (11 years ago)

Background Audio Questions How-To

Hi Folks. I've searched these forums and didn't quite find what I was looking for. Some issues/questions...want to get this resolve ASAP so I can finish off my BT app: - what value do you set to get the background audio to continue playing forever for a particular screen? I've tried putting in more than 1 for "Audio Number of Loops", but sometimes it works for a screen and sometimes not. Is it "-1"? - why is it that some plugins don't stop the background audio when you hit the BACK button in top navigation, eg Weather plugin, but some do (HTML Doc plugin). Is that because it's not programmed into the plugin? - Why is the background audio setting not exposed for all plugins? eg can't see it for Menu with Image, RD Simple RSS plugin, AppRater. I assume again this is due to it not being programmed into the plugin. But should this be a standard option for all plugins (where it is possible)? Maybe we need a standards document for plugins, and checks to ensure all plugins conform? - and the Biggie: why does the background audio stop for the Quiz plugin as soon as the countdown stops? I would like to have a background audio for the entire duration of a quiz until the user hits the BACK button to exist the quiz. Any suggestions on how to accomplish this? Thanks! Steve
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
05/08/13 01:00 PM (11 years ago)
This is what I did and works a treat, - Add array and string to Custom IOS Target Properties. - Add the following code in the audio.m file //Adds ability for audio to play even in screen lock NSError *setCategoryErr = nil; NSError *activationErr = nil; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryErr]; [[AVAudioSession sharedInstance] setActive: YES error: &activationErr]; - Remove following code from the delegate.m file //setup audio session for background sounds. Allow iPod to continue if it's already playing. [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil]; [[AVAudioSession sharedInstance] setActive: YES error: nil] These were the exact steps that allows for audio to be played in the background from streaming using customURL screen. All the best.
 
BuzzingSteve
Aspiring developer
Profile
Posts: 526
Reg: Jun 24, 2011
Vancouver, Cana...
11,660
like
05/08/13 01:06 PM (11 years ago)
Alex@TM. Thanks. I was hoping not to mess with the code :-) I basically want to have a different background audio file for each screen. Could you explain what your code does exactly? Cheers
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
05/08/13 01:14 PM (11 years ago)
My code allows for audio to play in the background. So if the phone sleeps, if you wish to navigate within the app or in other apps. It will however be the general rule for all audio within the app and wont be specific to each screen. If its what you want it is a very simple fix.
 
BuzzingSteve
Aspiring developer
Profile
Posts: 526
Reg: Jun 24, 2011
Vancouver, Cana...
11,660
like
05/08/13 01:26 PM (11 years ago)
Alex@TM. Thanks, and will keep this on file for a possible future app. But, I was hoping for a different background audio per screen, ie trying to get a feature to work in existing plugins :-) Do you know how to loop a audio file forever for a screen, and how to ensure the BACK button kills the audio? I guess a question for the plugin creators? :-) Cheers
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
05/08/13 01:31 PM (11 years ago)
Depends which plugin. Let me know which one and I'll take a look at the code. Will be something simple to kill the audio when the view is released.
 
BuzzingSteve
Aspiring developer
Profile
Posts: 526
Reg: Jun 24, 2011
Vancouver, Cana...
11,660
like
05/08/13 01:39 PM (11 years ago)
Alex@TM. That was the Weather plugin (background audio doesn't stop when you hit BACK). Also, I guess I need to get the following answered :-) Cheers - what value do you set to get the background audio to continue playing forever for a particular screen? I've tried putting in more than 1 for "Audio Number of Loops", but sometimes it works for a screen and sometimes not. Is it "-1" - it seems to stop after a certain number (which seems random based on plugin). - why is it that some plugins don't stop the background audio when you hit the BACK button in top navigation, eg Weather plugin, but some do (HTML Doc plugin). Is that because it's not programmed into the plugin? - Why is the background audio setting not exposed for all plugins? eg can't see it for Menu with Image, RD Simple RSS plugin, AppRater. I assume again this is due to it not being programmed into the plugin. But should this be a standard option for all plugins (where it is possible)? Maybe we need a standards document for plugins, and checks to ensure all plugins conform? - and the Biggie: why does the background audio stop for the Quiz plugin as soon as the countdown stops? I would like to have a background audio for the entire duration of a quiz until the user hits the BACK button to exist the quiz. Any suggestions on how to accomplish this?
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
05/08/13 01:49 PM (11 years ago)
This cn all be accomplished but you will need to speak with the plugin makers. I dont have the weather one yet so cannot take a look at it. Maybe it should be a feature that should be standard in all plugins. That said, I've never used audio in any plugin other than an audio/movie streamer so not sure the call for it warrants that, that said I dont know. I must admit, I thought all plugins audio would stop when exiting the screen as that is then playing in the background. Some must have been coded to work that way. Sorry to be of little use but its the plugin devs you need for specific questions like that. I could take a general look at the code in a plugin I have but when it is multiple plugins I think going to them will be the best approach. All the best.
 
BuzzingSteve
Aspiring developer
Profile
Posts: 526
Reg: Jun 24, 2011
Vancouver, Cana...
11,660
like
05/08/13 01:58 PM (11 years ago)
Alex@TM. No worries...I really think a standard for what features to expose via the Control Panel for plugins would help :-)
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
05/08/13 04:05 PM (11 years ago)
This has actually nothing to do with the ios code it is a control panel box, and is quite simple to fix if you are in self hosted, I will be adding this and iad to all of my plugins at some point. Adding the code will give you access to the audio. I belive for unlimited loop it is -1 Add this to any index.php to add the controls between any of the ########## to keep it safe Do this at your own risk, although if you mess up you just need to update the plugin. you will find the index.php files in BT_serverName >> files >> plugins >> thePLugin >> index.php <!-- ################################################################ --> <!-- ############### background audio properties #################### --> <div class='cpExpandoBox colorLightBg'> <a href='#' onClick="fnExpandCollapse('box_backgroundAudio');return false;"><img src='<?php echo APP_URL;?>/images/arr_right.gif' alt='arrow' />Background Audio</a> <div id="box_backgroundAudio" style="display:none;"> <table style='margin-top:10px;'> <tr> <td style='vertical-align:top;'> <b>Audio File Name</b> &nbsp;&nbsp; <img src="<?php echo APP_URL;?>/images/arr_right.gif" alt="arrow"/> <a href="<?php echo $controlPanelURL;?>/bt_pickerFile.php?appGuid=<?php echo $appGuid;?>&formEl=json_audioFileName&fileNameOrURL=fileName&searchFolder=/audio" rel="shadowbox;height=550;width=950">Select</a> <br/> <input type="text" name="json_audioFileName" id="json_audioFileName" value="<?php echo fnFormOutput(fnGetJsonProperyValue("audioFileName", $jsonVars));?>"> <br/><b>Audio File URL</b> &nbsp;&nbsp; <img src="<?php echo APP_URL;?>/images/arr_right.gif" alt="arrow"/> <a href="<?php echo $controlPanelURL;?>/bt_pickerFile.php?appGuid=<?php echo $appGuid;?>&formEl=json_audioFileURL&fileNameOrURL=URL&searchFolder=/audio" rel="shadowbox;height=550;width=950">Select</a> </br> <input type="text" name="json_audioFileURL" id="json_audioFileURL" value="<?php echo fnFormOutput(fnGetJsonProperyValue("audioFileURL", $jsonVars));?>" > </td> <td style='vertical-align:top;'> <b>Audio Number of Loops</b> (number)<br/> <input type="text" name="json_audioNumberOfLoops" id="json_audioNumberOfLoops" value="<?php echo fnFormOutput(fnGetJsonProperyValue("audioNumberOfLoops", $jsonVars));?>"> <br/><b>Audio Stops with "Back Button"</b><br/> <select name="json_audioStopsOnScreenExit" id="json_audioStopsOnScreenExit" style="width:250px;"> <option value="" <?php echo fnGetSelectedString("", fnGetJsonProperyValue("audioStopsOnScreenExit", $jsonVars));?>>--select--</option> <option value="1" <?php echo fnGetSelectedString("1", fnGetJsonProperyValue("audioStopsOnScreenExit", $jsonVars));?>>Yes, stop audio on screen exit</option> <option value="0" <?php echo fnGetSelectedString("0", fnGetJsonProperyValue("audioStopsOnScreenExit", $jsonVars));?>>No, keep playing on screen exit</option> </select> </td> </tr> </table> <div style="padding-top:5px;"> <input type='button' title="save" value="save" align='absmiddle' class="buttonSubmit" onClick="saveAdvancedProperty('saveResult_backgroundAudio');return false;"> <div id="saveResult_backgroundAudio" class="submit_working">&nbsp;</div> </div> </div> </div> <!-- ############### end background audio properties ################ --> <!-- ################################################################ -->
 
BuzzingSteve
Aspiring developer
Profile
Posts: 526
Reg: Jun 24, 2011
Vancouver, Cana...
11,660
like
05/08/13 04:11 PM (11 years ago)
@Kittsy. Ugh :-) Was hoping not to touch the code. LOL. I tried the "-1" value but it didn't seem to work. Thanks
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
05/08/13 04:13 PM (11 years ago)
Lol you'll have to touch the code or buy Harry potters book of spells see if that helps lol
 
BuzzingSteve
Aspiring developer
Profile
Posts: 526
Reg: Jun 24, 2011
Vancouver, Cana...
11,660
like
05/08/13 04:16 PM (11 years ago)
Already casting (cursing) a spell :-) Simple code ok...long code, not so much :-)
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
05/08/13 04:21 PM (11 years ago)
it's easy your copying all the code and inserting it no mods just adds
 
BuzzingSteve
Aspiring developer
Profile
Posts: 526
Reg: Jun 24, 2011
Vancouver, Cana...
11,660
like
05/08/13 05:50 PM (11 years ago)
I just think this should be done either at the plugin or control panel level. That way, everyone benefits and this doesn't need to be repeated for every app :-) Cheers
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
05/09/13 06:46 AM (11 years ago)
I just discovered this recently when I duped a plug-in and it had the audio properties in the index.php. I was adding my own code for bkg audio and was just planning to borrow Davids layout for these options. For kicks I threw in a file name and was amazed it worked. So then I had to remove my bkg audio code and just stick with this. This really shows the power of why BT is subclassing standard iOS classes - We've got bkg audio capability in ANY screen if we add this "code" which isn't even part of the plugins source code. Nice work David :)
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
05/09/13 07:03 AM (11 years ago)
Seems better than my work around!
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
05/09/13 07:17 AM (11 years ago)
^ I think your work around is what makes the streaming audio work even after you exit the app. I feel like adding that and commenting out the bkg audio in the delegate breaks it? Not sure, need to test on devices more. Emulator is no good for this. I feel like this streaming audio should be added to the BT core since it's really a critical feature of "Streaming". I thought maybe something had been added since the BTA streamer was released?
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
05/09/13 07:35 AM (11 years ago)
Nope, bta streamer was shutting down on sleep and exiting the app. However, it's such a great plugin I was only to happy to work out the work around :)
 

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.