mattgallagher / AudioStreamer

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

background Problem with playing more than one music URL #31

Open thiagoananias opened 13 years ago

thiagoananias commented 13 years ago

Hello, i'am trying to use the AudioStreamer in my project and i'am having some troubles with playing more than one music in background. Like this:

I start one music..so when it is finished starts another music...and it`s ok! But if i start one music and press the home button my app goes to background and the first musics keeps playing but when it tries go to the next song it stops...and only begins when i go back to the application.

I read something about AudioSession and i think thats why the fist music keeps playing...but im doing something to play the second music (which is other url) that i dont know if is right... when the player gets idle state - (void)playbackStateChanged: --> ([streamer isIdle]) I kill the player and inits another one...it works with the application opened but in background no...

Thanks.

bkill commented 13 years ago

That's normal. Your app will be able to run in the background only if there is audio playing. When the audio stops (ie: going to the next track), it will only resume when the player will go foreground again. To workaround this, you should control a separate background task ([[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:]) when the audio stops so you can do your stuff in between.

yasirmturk commented 12 years ago

i tried doing this.. but it say something like this when try to play next song Audio queue start failed. err: ÕG -12985

yasirmturk commented 12 years ago

Okay it fixed when i commented out AudioSessionSetActive(false);

`#ifdef TARGET_OS_IPHONE
//AudioSessionSetActive(false);

endif`

Ref: http://stackoverflow.com/q/3121841/140220