mattgallagher / AudioStreamer

A streaming audio player class (AudioStreamer) for Mac OS X and iPhone.
http://cocoawithlove.com
1.93k stars 553 forks source link

Backgroundaudio not working in iOS7 #85

Open JoergHamburg opened 10 years ago

JoergHamburg commented 10 years ago

AudioSessionInitialize ( NULL, // 'NULL' to use the default (main) run loop NULL, // 'NULL' to use the default run loop mode ASAudioSessionInterruptionListener, // a reference to your interruption callback self // data to pass to your interruption listener callback ); UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback; AudioSessionSetProperty ( kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory ); AudioSessionSetActive(true);

Functions are deprecated in iOS7. I tried to use AVAudioSession audioSession = [AVAudioSession sharedInstance]; BOOL ok; NSError setCategoryError = nil; ok = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionDidChangeInterruptionType:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];

ok = [audioSession setActive:YES error:&setCategoryError];

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; [appDelegate becomeFirstResponder];

but the audio still does not play when going to lock screen. Any advice on this?

Thanks in advanced, Jörg

dusker commented 10 years ago

I'm also having this issue, anybody managed to have a look at it?

ashleyevans commented 10 years ago

I noticed in the sample app the background audio capability isn't checked by default. Enabling this allowed the audio to play in the background as expected

I'd be really interested if someone has converted this to run on ios7 code successfully

Thanks

frakman1 commented 9 years ago

ashleyevans, I was able to get this to work on ios 8.1.3 if that is any help