Discussion Forums  >  Audio, Video, Playing, Recording

Replies: 23    Views: 214

Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
06/06/12 11:08 AM (13 years ago)

Adding Background Audio???

I cant seem to figure out how to add background audio to play in my app.? Can anyone help? I've searched the forums, but no sucsess. Any help would be appreciated. AM
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/06/12 01:26 PM (13 years ago)
Same issue. http://www.buzztouch.com/forum/thread.php?fid=C4A524DA8800FE415AF24BB&tid=C4A524DA8800FE415AF24BB I've successfully done it with soley changing the .plist and a webview in a native app. I'm sure it must be possible and I NEED to find the solution so continue to search!
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/06/12 02:41 PM (13 years ago)
If it helps the audio keeps playing if you use native app screen but you cant get back to the app. Does this give any clues away?!
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
06/06/12 02:53 PM (13 years ago)
.Alex, I wanted the music to play in the background as soon as the app launches. Can this be done.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
06/07/12 08:09 AM (13 years ago)
I was tinkering with this recently. Was going to add it in my app and then decided I hate when apps play background audio, so I shelved the idea. I wasn't doing this thru the BT Control Panel either. What I learned from reading many tutorials on doing Background Audio - is you need some type of screen/interface for the user to control the background audio. Somewhere they *could* turn it off or adjust the volume. Seemed like i was going to have to code that screen myself. So since I didn't like the concept or felt like writing more code, i just shelved it. But some stuff from my notes that might help you guys- Alex is on the right path i think. You seem to set-up the Background audio by adding a UIBackgroundModes to your app Custom IOS Target Properties. This is NOT the same as the Bt_info.plist. This is the Target properties 'info' screen where the Bundle Indentifier, Bundle Name and Icon File are stored. You add a row to this and call it UIBackgroundModes. Xcode will then magically change that row name and set-up an array with some dynamic fields and one is called APP Plays Audio. note: (I **HATE** this context sensitive/dynamic menu stuff. I'ts hard to find settings as it is, but esp when they don't show up unless you do something first. This is totally one of those scenarios) Then the next step that i never got to - you have to initialize the audio player and tell it the name of your audio file. I was looking at adding the code in one of these 2 areas- Application DidFinishLaunchingWithOptions in the main app delegate file or in the first screen of the app in the View DidLoad section (under the super.ViewDidLoad) maybe some of that might help you guys? I may do this and build that interface in a few weeks, but not right now. Keep me posted if you guys make any progress!
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/07/12 09:20 AM (13 years ago)
Thanks a lot ATRAIN, I will certainly take a look at this. It could be the perfect solution. The main radio app I use, tunein, plays background audio but doesnt have a screen to control it. I'm going to submit mine and see how I get on. I'll post any results, thanks again.
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/07/12 09:56 AM (13 years ago)
This worked!!!! Thank you so much. The question now is wether or not Apple will accept it. One way to find out! Thanks again.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
06/07/12 11:55 AM (13 years ago)
nice. hopefully that's what Rad Doc needs too then. def curious to hear if that passes the review. how did you make it work exactly? did you add the UIBackground mode to the Target Properties and copy the audio track to your project. how did you tell the app which audio file to use? and you can control the volume with the standard phone controls?
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/07/12 12:38 PM (13 years ago)
Its audio streaming for radio stations using the customURL plugin and pointing the url to the http address. I have coded something similar in an app I natively coded, not BT. For that I used a UIWebView with NSURL calling the stream. As with the customURL plugin it uses the devices in built QT player to play the stream. Simply changing the info.plist sorted out the background audio on the native app. I was essentially trying to do the same thing within BT. So, changing it as you suggested not in the info.plist did the trick. As with native, it uses the QT player to play the stream. Yup, the phone controls work to control the volume. Check out Radio23.org They made an app here using the same method. Ive downloaded the app and it uses the QT player but turns off when the device sleeps, locked or come out of the app. Maybe apple wont like background audio but it is appropriate in this case so it should be ok. All the best.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
06/07/12 01:42 PM (13 years ago)
nice. so we've essentially got streaming background audio in the app using the Custom URL plugin. you put the link in Custom URL screen to the streaming URL. then you just you added the UIBackground mode to the App Traget Settings for "APP Plays Audio" and it works? wow. trying to figure put how that app knows to launch that URL on start-up. i will give your steps a test soon myself and maybe understand it better then. feel like i'm missing a piece, but glad my notes were of use. the app making stuff is a lot of patchwork from here/there isn't it! hope that app passes review - let me know please!
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/07/12 02:06 PM (13 years ago)
Sorry no, that was a mistake, I made some further alterations. So the steps are: - 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.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
06/08/12 07:25 AM (13 years ago)
perfect. thanks for those last notes and actually getting this working! filing this away for future use. if i get around to coding up a screen to control the player, i'll post back here or throw up a new thread. gonna be a bit. what i'm thinking is to link to my background player control page from the top nav bar with something like a music note icon. and then make that screen with the player controls a new plugin. question would then be are users smart enough to associate that 'music note' with the background audio to control it. maybe some text on the screen to note this.....
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
06/18/12 02:43 AM (13 years ago)
Alex, I have a streaming audio app that stops playing during auto close. My audio is linked to custom url links that stream from my server. I tried to add the code to my app delegate.m file and removed this-//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]. I tried to lock the screen and it stops playing. Any thoughts. Should i be adding this code the the audio.m file even bought i am streaming? If so, where? Line #? Thanks Anthony
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/18/12 02:49 AM (13 years ago)
This is what I did: - 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.
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
06/18/12 02:54 AM (13 years ago)
Alex, Where about did you add the code to the audio.m file? Drop it anywhere? Line #? Trying to get a landmark where to insert. Thanks for your help
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/18/12 03:02 AM (13 years ago)
After this.. //center cotnrols in this box UIView *controlBox = [[UIView alloc] initWithFrame:CGRectMake((self.view.bounds.size.width / 2) - (boxWidth / 2), 0, boxWidth, topBoxHeight)]; controlBox.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin); [controlBox setBackgroundColor:[UIColor clearColor]];
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
06/18/12 03:05 AM (13 years ago)
Thanks you for your help. Gonna give it a shot. Anthony
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/15/12 03:07 PM (13 years ago)
Thank you both for helping me get this!!! HUGE!!
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
07/15/12 03:33 PM (13 years ago)
No problem, glad you got it working. Forgot to report, the update went through fine with the radio integrated. http://itunes.apple.com/us/app/freestyle-scooters/id499371179?ls=1&mt=8 All the best
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/15/12 04:05 PM (13 years ago)
Will download right now.
 
Briton
Aspiring developer
Profile
Posts: 13
Reg: Jan 13, 2012
Pensacola
2,280
like
08/14/12 08:13 AM (13 years ago)
Alex - what version of buzztouch did you use to make your app?
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
08/14/12 09:19 AM (13 years ago)
V 1,5
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
08/14/12 09:20 AM (13 years ago)
Making a radio specific app now, solely radio stations to a pre determined genre to hopefully target sales. Will get some codes up when and IF its accepted by apple. Still in development so might be a while yet.
 
Briton
Aspiring developer
Profile
Posts: 13
Reg: Jan 13, 2012
Pensacola
2,280
like
08/14/12 09:40 AM (13 years ago)
Fantastic, thanks. I have found that advertisers are very receptive to advertising on our app, though you have to figure out pricing for the market. Our sweet spot for now is $5 per thousand accesses, sold as week long average.
 

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.