2

Everybody knows the standard procedure to keep your app alive, after the user pressed the lock button (silent sound). If I start a sound with AVAudioPlayer (before the iphone is locked), the sound plays till it's end (after locking). The app is still running. If I try to start another sound while the iPhone is locked, it will never get played. All the other things work as well but the sound doesn't.

How can I play a sound while the iphone is locked?

Joe Mallik
  • 23
  • 1
  • 3
  • So, why do you want to keep your app alive? If you dont plan to make some kind of trackingsystem i see no reason for that. If you need some data on startup, use an sqlite-table or the coredata-framework! –  May 26 '10 at 14:30
  • There are lots of reasons to keep an app alive besides a tracking system. – progrmr May 26 '10 at 15:29

3 Answers3

0

If the problem is that your app is doing to sleep after the screen locks, then this question is already answered here and here on SO

Community
  • 1
  • 1
progrmr
  • 75,956
  • 16
  • 112
  • 147
  • The question isn't answered yet. IdleTimer isn't an option and the audio session is configured quite the same as in your example. The problem is, if the phone is locked, i can't initiate a new sound. I can play a sound (code execution works) but you can't hear it. – Joe Mallik May 27 '10 at 06:14
  • @Joe you should be able to play sounds when the screen is locked, you don't need to disable the idle timer, but you have to keep playing sound. My [app](http://clocksmith.mggm.net) plays a silent sound every 10 seconds to prevent deep sleep. To verify your problem, let your app run on the device until it stops working, then attach your phone to xcode via usb and look at the console log in the organizer, you'll see the OS shutting everything down and putting the system to sleep. The only way (before OS 4) is to keep playing sounds every 10 seconds or so. – progrmr May 27 '10 at 12:25
  • Look at [this log](http://bit.ly/axF0He), if this is what is happening to your app, then you need to play sounds more often to keep it alive. – progrmr May 27 '10 at 12:37
  • Yes, I did it your way (play a silent sound), but I want to play another unplayed sound later. This sound is inaudible. It's not the problem to keep the app alive. – Joe Mallik May 27 '10 at 16:18
  • Perhaps I misunderstood the question then... I thought the app was going to deep sleep and thus the sound was not playing. Can you see log entries on the console to verify the app is still running and tries to play a sound but you hear nothing? Is that the problem? – progrmr May 27 '10 at 16:29
  • @JoeMallik I dont understand, why is this checked off? What would the answer be? And is it verified in iOS 5, which now handles this differently. – Andres Canella Sep 19 '12 at 01:46
0

I'm not sure where your problem is, but have you set up the audio category to allow mixing?

const UInt32 categoryProp = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(categoryProp), &categoryProp);

UInt32 category = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);

const UInt32 setProperty_YES = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(setProperty_YES), &setProperty_YES);
progrmr
  • 75,956
  • 16
  • 112
  • 147
0

Now all works fine! I missed a log statement. It seems I flooded the audio buffer!

Thanks to all who tried to help me fixing this.

Joe Mallik
  • 23
  • 1
  • 3