Discussion Forums  >  Audio, Video, Playing, Recording

Replies: 34    Views: 139

Njmpwnz
Apple Fan
Profile
Posts: 165
Reg: Feb 08, 2011
Cleves
2,350
06/26/12 10:18 AM (13 years ago)

I want BG audio to always play

I would like it if my background audio would play when you exit the app or the iPhone/iPad locks itself. I'm all about battery so I won't do the thing to prevent it from locking. I know there's a way to do it. Pandora does.
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
06/26/12 11:19 AM (13 years ago)
- 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]; Put the above code after this in the audio.m file...It’ll work perfect //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/26/12 11:24 AM (13 years ago)
It should look like 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]]; //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];
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
06/26/12 11:30 AM (13 years ago)
Good man Rad Doc, great info!
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
06/26/12 11:40 AM (13 years ago)
I must give credit where credit is due, and that is to @Alex TM for showing me how to solve this problem. Glad i was able to help.
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
06/26/12 05:39 PM (13 years ago)
Pasted in the exact same location...nothing. I am on BTv1.5 iOS using a Streaming Audio Screen. Any advice? It seems so straight forward...not sure what I am doing wrong. Thank You ******is this only for background audio?
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
06/26/12 06:09 PM (13 years ago)
Isills, No its not. I use this code for an iOS v1.5 streaming audio music app and this code works perfectly. Open Xcode, find your audio.m file and add this code exactly where i mentioned earlier. Keep me posted.
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
06/26/12 06:13 PM (13 years ago)
@njmpwnz, Did it work for you?
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
06/26/12 06:39 PM (13 years ago)
Did that before I posted. Here is a screen capture. Thank you. http://cl.ly/0F0D1L3d1v1q211L0j46 that is the "BT_screen_audio.m" file where I added that code.
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
06/26/12 07:14 PM (13 years ago)
Did you do a clean and build? Is music playing at all?
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
06/26/12 07:22 PM (13 years ago)
yes music is playing fine...did a full clean and run. ****do I need to select the audio plays in other screens option?
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
06/26/12 07:29 PM (13 years ago)
Try adding this to your target info plist.You need 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.
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
06/26/12 07:36 PM (13 years ago)
Got it...thank you. Will update soon. Thanks again!!!
 
Njmpwnz
Apple Fan
Profile
Posts: 165
Reg: Feb 08, 2011
Cleves
2,350
like
07/05/12 12:15 AM (13 years ago)
How do I do it on 2.0?
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/10/12 01:45 PM (12 years ago)
I did exactly as you said...however I do not have "APP Plays Audio"
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/10/12 02:11 PM (12 years ago)
I did exactly as you said...however I do not have "APP Plays Audio" in the Targets>>Info>>Custom iOS Taget Properties. It changes the name to "Required background modes" and adds an Array. Any help would be greatly appreciated. Thank you
 
Njmpwnz
Apple Fan
Profile
Posts: 165
Reg: Feb 08, 2011
Cleves
2,350
like
07/10/12 02:58 PM (12 years ago)
Audio.m is not in 2.0. How can I do it on BT2.0?
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/10/12 03:10 PM (12 years ago)
@njmpwnz I have tried to just get the music to stream in 2.0 but gave into 1.5....what plug-in did you use?
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
07/10/12 04:03 PM (12 years ago)
Guys, Im using IOS v1.5 still. Installed self hosted panel but not totally crazy for all its features yet. @Isills, In Xcode, In Target>info>required background modes, hit the arrow down to open up item 0, and then hit the arrow up/down on the right side of that row to key to choose app plays audio. I attached a screenshot for you. Hope this helps. I used a custom url screen to run my audio. http://dl.dropbox.com/u/35241128/Sample%20Screenshot/app%20plays.png Anthony
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/10/12 04:21 PM (12 years ago)
WOW!!! That was that last step I needed. Thank you!!! I am going to make a video tutorial for this. I will credit you for it!!!! THANK YOU
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
07/10/12 04:28 PM (12 years ago)
Anytime pal. We're here for each other. Maybe I can get someone to help me implement this socialize feature I'm having so much trouble with into my app. Glad i was able to help.
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/10/12 04:50 PM (12 years ago)
Scringo... Is that what you are working with on?
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
07/10/12 04:57 PM (12 years ago)
Was playing with Socialize and can't seem to get it to work properly. Running into 22 fail errors when I run it. Do u like scringo. Is it as interective as socialize as far as commenting and adding posts to Facebook.
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/10/12 05:02 PM (12 years ago)
Maybe I can return the favor...here is a tutorial where I go from start to finish. http://www.youtube.com/watch?v=bENvJlt0eps and the text file http://cl.ly/193w151T0V2R0k3S2L2U
 
Njmpwnz
Apple Fan
Profile
Posts: 165
Reg: Feb 08, 2011
Cleves
2,350
like
07/10/12 07:25 PM (12 years ago)
Audio.m is not in 2.0. How can I do it on BT2.0?
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/10/12 07:31 PM (12 years ago)
@njmpwnz what plugin did you use to stream your audio and I will help you?
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
07/11/12 09:58 AM (12 years ago)
@Isills, Got Scringo to work. How can I now incorporate twitter and FB Feeds?
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/11/12 12:23 PM (12 years ago)
I actually removed it from my app after I installed it....I have some links at my house that I will get to you. They will show you how to incorporate Facebook. One thing I do know is you need to have a Facebook App set up.....have you done that?
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
07/11/12 12:38 PM (12 years ago)
Yes. BTW, Whhat swayed you to remove it?
 
Njmpwnz
Apple Fan
Profile
Posts: 165
Reg: Feb 08, 2011
Cleves
2,350
like
07/14/12 06:14 AM (12 years ago)
its a custom HTML/text screen with BG audio
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/15/12 12:13 PM (12 years ago)
I had to add a "Streaming Audio" screen before this would work with a "Custom URL - Webpage" screen....the first app I put this in had a .mp3 file that I wanted to play after the device was closed so the Custom URL wasn't needed. The next app I built has streaming feed from a website and it would NOT play in the background until I added the "Streaming Audio" screen. It's not an active screen and this app is Tab Layout so i just DON'T give it a tab and it is invisible to the end user. Weird but not a bug....I would bet there are files needed in the "Streaming Audio" screen that are needed for the change in the audio.m file to take effect....just my opinion. EDIT**** if I re-save the tabbed layout or or run the Xcode project after I delete the "Streaming Audio" screen reference it breaks the code and won't play the music after I close the app. I had to add the "Streaming Audio" screen back to my tabbed layout and then refresh the app and then delete the "Streaming Audio" screen reference in the Tabbed Layout screen to get audio after the app is closed. I am only using a 4 tabbed layout...if I had 5 I would have to figure out another way. Any ideas? thanks
 
Njmpwnz
Apple Fan
Profile
Posts: 165
Reg: Feb 08, 2011
Cleves
2,350
like
07/15/12 03:48 PM (12 years ago)
it sounds to me like you're working with Buzztouch 1.5. I need a solution to this issue using a custom HTML screen with background audio in the form of an mp3 file. my app needs to be able to play that while the device is locked. I use 2.0 so there is no audio.m file in my app. How do I fix this?
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/15/12 04:06 PM (12 years ago)
I can't help with the lack of no audio.h file but I fixed this error and will have a tutorial up in a few. There was a step left out.
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
09/13/12 02:50 PM (12 years ago)
Got it to work on 2.0 here: http://www.buzztouch.com/forum/thread.php?tid=3F88D90DE1271FA362A3C4F Thanks! David buzztouchmods.com
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
09/13/12 03:49 PM (12 years ago)
Word @David
 

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.