Discussion Forums  >  Uncategorized

Replies: 42    Views: 740

ThomasSechak
Aspiring developer
Profile
Posts: 59
Reg: Jul 10, 2011
Charlottsville
10,690
08/11/11 07:58 AM (12 years ago)

Audio Playback Even When Auto-Lock Turns On

Hi I am using BuzzTouch Ver 1.5, with Xcode 4.0.2. I have created my first app which is just about finished. It is an app that plays back a 10 minute audio file located in the file system, not streaming. One thing remains for me to fix for it to be finished. The audio stops when the Auto-Lock on an iPhone or iPad turns on. How can I make it run even when the auto-lock turns on. I searched this forum and found something to try which is a new string in the BT_info.plist file: Key: UIBackgroundModes Type: string Value: audio But this did not fix it. Maybe I did it wrong. Should that work. If not what can I do to make the audio play back when auto-lock turns on. I found a document a PDF at apple dev site called MultimediaProgrammingGuide.pdf It mentions putting code in during initializing, but I don't know if this works with a BuzzTouch app or not, or even where to put it if it would work. here is what the doc says; For example, when using the default audio session, audio in your application stops when the Auto-Lock period times out and the screen locks. If you want to ensure that playback continues with the screen locked, include the following lines in your application’s initialization code: NSError *setCategoryErr = nil; NSError *activationErr = nil; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryErr]; [[AVAudioSession sharedInstance] setActive: YES error: &activationErr]; Can you give some guidance, I am new to this so I am not sure if I can do anything complicated right now, but I will try if needed. Thanks in advance. Thomas
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/12/11 01:45 AM (12 years ago)
I posted this on the other discussion, ignore it if you already read it. I totally understand, audio should just keep playing in most cases. We never did figure out a way to make this setting easy in the control panel because most apps that use audio use a bunch of different tracks and it gets super-confusing (programming wise) to work around. Maybe we'll get it at some point? In the meantime, it's all about what iOS calls an Audio Session. When the audio starts you can instruct your app (with code) to begin an Audio Session. This helps the device understand what to do with your audio when things happen...like earphones plugged in / out , app to background, etc. Google Audio Session iOS and see if you can get anywhere. So, it looks like you did figure out that the Audio Session is where to start. Not sure how to best advise. The AVAudioPlayer initializes in the BT_screen_audio.m file. Have a look at that file. You'll end up starting your session when the audio player is initialized.
 
ThomasSechak
Aspiring developer
Profile
Posts: 59
Reg: Jul 10, 2011
Charlottsville
10,690
like
08/12/11 05:01 AM (12 years ago)
Thanks, this should help quite a bit, I now know which file to experiment with. Now I just need to figure out in which part of the file to put the code in without breaking things, and do I need to add brackets and things around it. Thanks for your help.
 
ThomasSechak
Aspiring developer
Profile
Posts: 59
Reg: Jul 10, 2011
Charlottsville
10,690
like
08/12/11 07:59 AM (12 years ago)
Thanks for the info. I got it working I put the code in the BT_Screen_Audio.m file as you said. I will post below exactly what I did incase someone else want to do it also. 2 Things to do to make this work. Or waht I did to make this work is In the BT_Screen_Audio.m file put in the code: //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]; I put this under the section //center cotnrols in this box After this I added a new string in the BT_info.plist file: Key: UIBackgroundModes Type: string Value: audio Hope people find this helpful. Thanks for a great service and your assistance.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/12/11 10:40 PM (12 years ago)
You're welcome. Awesome post!
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
08/14/11 05:15 PM (12 years ago)
Thank you @Thomas777 - Very helpful :)
 
Arock
I hate code!
Profile
Posts: 35
Reg: Aug 27, 2011
Woodhaven
350
like
09/01/11 06:45 PM (12 years ago)
Hi Thomas and David. I'm trying to make this work but when I look in my Xcode project I don't see any folders named BT_Screen_Audio. In fact I don't see ANY BT folders. I see a fold named SCreenControllers and inside I see Screen_About, Screen_ShareFaceBook, Screen_ShareEmail, etc. etc. but no Screen_Audio. I have a streaming audio submenu setup in my app that links to a shout cast url. It works fine when I start it up...goes right to quicktime....but I need to make it so that it continues to play when the iPod or iPhone auto-locks. Any help, please? :)
 
ThomasSechak
Aspiring developer
Profile
Posts: 59
Reg: Jul 10, 2011
Charlottsville
10,690
like
09/02/11 04:52 AM (12 years ago)
Hi Arock Here is a link to a screen shot with what my folders look like, and with an arrow pointing to the BT_Screen_Audio.m file. I am new to BuzzTouch and making Apps in general so if folders and files are not appearing in your project I would not have any idea as to why. http://www.synchronicity.org/picts/Capture.JPG But perhaps the screen show above will provide the information you need to find the file located in the BT_Screens folder. Good luck with you app.
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/02/11 05:19 PM (12 years ago)
Thanks Thomas... just used your code worked great first time... Question what was the need for this extra code? I did not add the Key: UIBackgroundModes Type: string Value: audio in the BT_info.plist file and all seems to be working great... will I pay the price later?? thanks again.. Ross
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
10/02/11 08:35 PM (12 years ago)
It's all about managing what iOS calls an Audio Session. This may help eplain the info.plist additions... http://developer.apple.com/library/ios/#DOCUMENTATION/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html
 
ThomasSechak
Aspiring developer
Profile
Posts: 59
Reg: Jul 10, 2011
Charlottsville
10,690
like
10/03/11 04:04 AM (12 years ago)
Hi Yes, I believe it was needed so iOS knew that the app has that functionality. Good luck with you app.
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/03/11 10:05 PM (12 years ago)
I'm having a problem uploading to iTunes with the value audio: Key: UIBackgroundModes Type: string Value: audio Getting this error message: the value for the Info.plist key UIBackgroundModes is not of the required type for that key. Any ideas??? thanks
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/03/11 11:20 PM (12 years ago)
Got it...It needed to be in an array and had to added as a new key in xcode ... I had just edited the xml file... oh well... just learning :~)
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/08/11 09:23 PM (12 years ago)
Hi Thomas Where do I cut and paste this? //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]; This is what is currently showing... //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]]; Cheers Terry
 
ThomasSechak
Aspiring developer
Profile
Posts: 59
Reg: Jul 10, 2011
Charlottsville
10,690
like
10/09/11 04:55 AM (12 years ago)
Below are three sections in the In the BT_Screen_Audio.m. This shows the section above and the section below. Hope this helps //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]; //status label audioStatusLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 25, boxWidth, 20)]; audioStatusLabel.font = [UIFont systemFontOfSize:15]; audioStatusLabel.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin); audioStatusLabel.backgroundColor = [UIColor clearColor]; audioStatusLabel.textColor = [UIColor whiteColor]; audioStatusLabel.textAlignment = UITextAlignmentCenter; audioStatusLabel.text = @; [controlBox addSubview:audioStatusLabel];
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/11/11 03:08 AM (12 years ago)
Thanks Thomas I cut and pasted the code like you instructed but still, when I close my app, the audio stops as well :( Terry
 
ThomasSechak
Aspiring developer
Profile
Posts: 59
Reg: Jul 10, 2011
Charlottsville
10,690
like
10/11/11 04:24 AM (12 years ago)
Did you also add the array string in the info file Key: UIBackgroundModes Type: string Value: App Plays Audio These two things should produce the following results Will keep playing Keeps playing when screen lock comes on Keeps playing when app is minimized Will stop playing Stop playing if its a phone and a call comes in I believe it will also stop playing the audio if another multimedia app starts playing
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/11/11 07:49 PM (12 years ago)
Thanks for your continuing help. How do I add the array string in the info file?
 
ThomasSechak
Aspiring developer
Profile
Posts: 59
Reg: Jul 10, 2011
Charlottsville
10,690
like
10/12/11 04:17 AM (12 years ago)
Here is a link to an image that shows what it looks like once made. This should probably show enough for you to work it out. http://www.synchronicity.org/downloads/XCodeArrayString.JPG Info.plst - add required background modes then array - then with the array selected right click and select add new row, then add the app plays audio string.
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/13/11 04:28 PM (12 years ago)
Sorry to be dumb, where do I find the info.plst?
 
ThomasSechak
Aspiring developer
Profile
Posts: 59
Reg: Jul 10, 2011
Charlottsville
10,690
like
10/13/11 04:32 PM (12 years ago)
It shows in the screen shot... the link in my previous post. Click on targets in the project, then click on info. This is how it was in my version of XCode. I am new to XCode and Apps. So if you have a different version than me that looks different then I have no idea where it would be.
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/13/11 04:57 PM (12 years ago)
What version of Xcode do you have?
 
ThomasSechak
Aspiring developer
Profile
Posts: 59
Reg: Jul 10, 2011
Charlottsville
10,690
like
10/13/11 05:08 PM (12 years ago)
I have the latest version of XCode, but its on a different computer that I don't have access to right now. I am not a Mac fan, I use windows and it is on a Mac that I use only when necessary.
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/13/11 05:28 PM (12 years ago)
you can access it also from the BT_Config folder. That's how I added it... :-)
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/13/11 05:43 PM (12 years ago)
Ah excellent rossideas - Found it. Now how would I add Key: UIBackgroundModes Type: string Value: App Plays Audio to the array string in the info file ?
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/13/11 05:51 PM (12 years ago)
I had found a tutorial on it, but if I remember right it was 2 steps: - I right clicked on the bottom row to add UIBackgroundModes Array - then you add an item 0 string = audio I think once you get there you will figure it out pretty quick
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/16/11 05:46 PM (12 years ago)
Still stuck, sorry! When you say you right click on the bottom row; the bottom row of what? Thanks
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/16/11 05:54 PM (12 years ago)
open the BT_Config folder highlight BT_info.plist (you will then see to the right...Rows labeled, Key - Type - Value) Then right click on the bottom row...and follow what I wrote above...
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/16/11 06:03 PM (12 years ago)
Cant see that option Here is what it shows me http://twitpic.com/71iqzu
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/16/11 06:10 PM (12 years ago)
Sorry... right click add a row and name it UIBackgroundModes then the drop down arrows add array then click drop down arrow just left of UIBackgroundModes then you add an item 0 string = audio
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/16/11 06:21 PM (12 years ago)
It does allow me to add a row http://twitpic.com/71iwa6
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/16/11 06:48 PM (12 years ago)
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/16/11 07:06 PM (12 years ago)
AWESOME ! I will try this tonight and let u know how I go... So nice of you to post this. Really appreciate it :)
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/16/11 08:02 PM (12 years ago)
Sure. This is an awesome forum with everyone helping. Make sure you don't copy my happy face at the end of the link... hahaha..
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/17/11 04:42 PM (12 years ago)
Ok, did everything but when I exit the app in the sim, the audio still quits as well :(
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/17/11 05:02 PM (12 years ago)
There is a setting in BT Audio stops on screen change choose what you'd like to have happen...
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/17/11 05:15 PM (12 years ago)
Yes its been set to No keep playing on screen changes since day 1 Oh well (deep sigh...)
 
rossideas
Aspiring developer
Profile
Posts: 145
Reg: Jul 24, 2011
Albuquerque
1,450
like
10/17/11 06:45 PM (12 years ago)
Now, I just did a test and in the simulator when I hit the exit button the audio does stop but when I hooked up my iPad to the SDK and hit exit, the audio keeps playing. My app that uses the above code has worked from day one, but I rarely use the simulator and use my devices 99% of the time.. you may need to test on an iPhone/iPad... it may be working... Ross
 
Jennyapps
I hate code!
Profile
Posts: 222
Reg: Jun 12, 2011
Tasmania, Austr...
4,870
like
10/19/11 07:45 PM (12 years ago)
OUTSTANDING ROSS! I had a feeling it was the sim... Problem is I have been using Xcode 3.2.6 so when I updated my dev phone to iOS5 it made my sdk invalid. I have to download Xcode 4.2 which is 1.65 gig so have to wait until end of month as I have used up all my data. Will let u know when I do, and once again a BIG thank you :)
 
Laurand
Apple Fan
Profile
Posts: 34
Reg: Jan 30, 2012
Around here
340
like
02/17/12 01:30 PM (12 years ago)
Hello all ! I did exactly the following of above with xcode and on device, nothing happened it keeps stop the audio on screen lock, that's a grrrrrrr. I'm stuck in here, please if anyone would give a hand and help with, i will be very appreciated. Thank you.
 
Laurand
Apple Fan
Profile
Posts: 34
Reg: Jan 30, 2012
Around here
340
like
02/21/12 11:29 PM (12 years ago)
Hello, finally after many tested methods i found a way and now it works playing audio in the background when the screen locks. I did all the audio requirements with info.plist, and then i open BT_Config appDelgate.m i scrolled down until i found the coding. //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 selected and removed whole this code you see above, that was all it plays the audio in background, hope so that is not a issue but my app is in review by today.
 
rdrye2000
Code is Art
Profile
Posts: 24
Reg: Jan 08, 2012
Atlanta
240
like
05/08/12 07:41 PM (11 years ago)
Laurand...did this work when you submitted to Apple? I have also followed the above instructions and it is not working. I'm about to try your fix
 
rdrye2000
Code is Art
Profile
Posts: 24
Reg: Jan 08, 2012
Atlanta
240
like
05/08/12 09:31 PM (11 years ago)
Has anyone else had trouble with this solution? iOS
 

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.