mattgallagher / AudioStreamer

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

iOS4 Multitasking with AudioStreamer #7

Open markst opened 14 years ago

markst commented 14 years ago

I know this isn't an issue, but I couldn't work out how to add a comment any other way...

How would I implement this class to allow background streaming with iOS4?

Thanks.

Mark

zliuva commented 14 years ago

it comes out of the box (there's an background-enabled iPhone example in this fork: http://github.com/jfricker/AudioStreamer), just add "audio" key in Info.plist, also you have to have the playback started at least once before your app enters background for it to work

mbrucedogs commented 14 years ago

The one issue I have found with the AudioStreamer and this project also would have the problem is implementing a "Pause" function instead of using the Stop. The issue I have found with using pause is that in iOS4 if you pause the stream and have the app in the background this will affect other applications audio sessions.

Try to add pause to this app instead of using Stop and you will see what I am talking about. Pandora is the only app that I have seen that has solved this issue. Other Streaming apps are just doing a Stop which doesn't work if you are listening to a individual stream of a song and not a station. Example streaming a .mp3 file from a website.

loic-prieto commented 13 years ago

I don't know where else to look. I'm using the audio streamer to play a radio in my app. It all works fine until i go to background mode. There it still plays for some random time (from 1 minute to 10) and then it stops. If i resume my app, the stream is also resumed and continues to play. Why should this happen? i've set nslogs everywhere in the audio streamer. I've put audio as an item in the UIBackgroundModes plist array, as instructed here. I think the problem has something to do with a network condition that happens wich causes the stream to pause, and then it doesn't resume. Perhaps buffering is not allowed in background? I don't know how to check what happens.

edit: i've run more tests. If i upgrade my wifi connection to a better one (the first connection i tested was somewhat poor) the background streaming lasts a lot more. I'm starting to think that this issue appears when a buffering occurs while in background mode. In foreground mode buffering works by just pausing sound until the buffer is complete again and then resumes. When in background mode, buffering stops completely until i get to foreground again. Also, one of the last times i got the sound in the background stopped, the last nslog in the console window was showing a call to setState with a value of 6 (buffering).

jocull commented 13 years ago

Is this background stream supposed to work on the simulator with your fork? I can't seem to get it to work. The app is clearly running in the background, but the audio stops playing (pauses) when the app is put away. It resumes where it left off when bringing the app back up.

jocull commented 13 years ago

My mistake, it appears that background audio doesn't work on the simulator. It does work on a real device, however. I just tested it.

genzeb commented 13 years ago

@mbrucedogs take a look at mattgallagher/AudioStreamer#26 for your pause/audio-interruption issue.