AudioStreamer not working in background in iOS5. A

2019-09-06 18:42发布

问题:

I have implemented Audiostreamer class of Matt Gallagher in my application and it works fine in ios4. But when I switched to iOS5 the background playing is not working in there.

I have added UIBackground Modes and Application does not run in Background plist values to my application. So I think the issue is something else.

回答1:

it wont work in simulator, you're not in simulator are you?



回答2:

@j_mcnally iOS5 Simulator supports background playing.

@thoughtbreaker In Matt Gallagher there are some flows. Does your audio not play in the background at all or it stops after one track is finished playing.

If its not playing at all in the background than there may be buffering related problem... You should use Background expiration handler, in your audioStateChange method, but only when app is in the background.

UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:nil]

}]; 

You can check the background mode by setting a global flag in applicationDidEnterBackground method

Also invalidate the handler in your audioStart Playing method

[app endBackgroundTask:bgTask];