heysamhey heysamhey - 1 year ago 189
iOS Question

UIWebView: HTML5 audio pauses in iOS 6 when app enters background

Good day,

My app is a music playing app. I control the

-Tag with Javascript. So far no problems, play, pause, next and previous buttons are working. When I stand-by the device in iOS 5, the music keeps playing, but the automatic next song doesn't work. When it isn't in stand-by, it works. And in iOS 6, just after pressing the button, the music fades out.

The Play/Pause button on the lockscreen works in iOS 5, but not in iOS 6.

Answer Source

Starting with iOS 6, you MUST set the audio session category to 'playback' before creating the UIWebView. This is all you have to do. It is not necessary to make the session active.

This should be used for html video as well, because if you don't configure the session, your video will be muted when the ringer switch is off.

#import <AVFoundation/AVFoundation.h>

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL ok;
NSError *setCategoryError = nil;
ok = [audioSession setCategory:AVAudioSessionCategoryPlayback
if (!ok) {
  NSLog(@"%s setCategoryError=%@", __PRETTY_FUNCTION__, setCategoryError);

Ensure that your target links to the AVFoundation framework.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download