Discussion Forums  >  Audio, Video, Playing, Recording

Replies: 5    Views: 82

Njmpwnz
Apple Fan
Profile
Posts: 165
Reg: Feb 08, 2011
Cleves
2,350
07/05/12 12:29 AM (13 years ago)

BG audio stopping on 2.0 when locked

I would like it if my background audio would play when you lock the iPhone/iPad 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.
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
07/05/12 05:14 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]]; No credits to me through, here is the source! http://www.buzztouch.com/forum/thread.php?tid=FE4DEC41BB3C34F3575D4A3&currentPage=1 Cheers, David buzztouchmods.com
 
Njmpwnz
Apple Fan
Profile
Posts: 165
Reg: Feb 08, 2011
Cleves
2,350
like
07/05/12 01:23 PM (13 years ago)
Is there an audio.m in 2.0? I'm not seeing one.
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/15/12 02:52 PM (13 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 from the Tabbed Layout 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
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/15/12 03:04 PM (13 years ago)
This was the reason here....the directs on here for this are scattered but it works now!! Thank you to @AlexTM @RadDoc - 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]
 
lsills81
Apple Fan
Profile
Posts: 469
Reg: Mar 19, 2012
location unknow...
14,090
like
07/16/12 08:04 AM (13 years ago)
@njmpwnz: Try the code in the BT_audioPlayer.m file that's in the BT_Core folder. The box for controls starts at line 95 and that code looks similar to where you have it in the 1.5. I'm curious to test this myself and see what kind of controls you get for the audio.....hopefully later this afternoon.
 

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.