Bug 127137

Summary: [iOS] HTMLMediaSession should set AudioSession category
Product: WebKit Reporter: Eric Carlson <eric.carlson>
Component: MediaAssignee: Eric Carlson <eric.carlson>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, esprehn+autocc, glenn, gyuyoung.kim, jer.noble
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Proposed patch none

Description Eric Carlson 2014-01-16 13:08:44 PST
On iOS, an HTMLMediaElement should always set the audio category to "media" so the ringer switch and volume controls do the right thing.
Comment 1 Eric Carlson 2014-01-16 13:27:21 PST
Created attachment 221406 [details]
Proposed patch
Comment 2 Sam Weinig 2014-01-16 22:04:23 PST
Comment on attachment 221406 [details]
Proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=221406&action=review

> Source/WebCore/html/HTMLMediaSession.cpp:58
> +#if PLATFORM(IOS)
> +static void initializeAudioSession()
> +{
> +    static bool wasAudioSessionInitialized;
> +    if (wasAudioSessionInitialized)
> +        return;
> +
> +    wasAudioSessionInitialized = true;
> +    if (!WebCore::applicationIsMobileSafari())
> +        return;
> +
> +    AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
> +}
> +#endif

Why do we only want to do this on iOS (and only in MobileSafari)?

> Source/WebCore/html/HTMLMediaSession.cpp:71
> +#if PLATFORM(IOS)
> +    initializeAudioSession();
> +#endif

I would rather we always call this, and have it do nothing on platforms that don't need it.
Comment 3 Eric Carlson 2014-01-17 10:28:28 PST
(In reply to comment #2)
> (From update of attachment 221406 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=221406&action=review
> 
> > Source/WebCore/html/HTMLMediaSession.cpp:58
> > +#if PLATFORM(IOS)
> > +static void initializeAudioSession()
> > +{
> > +    static bool wasAudioSessionInitialized;
> > +    if (wasAudioSessionInitialized)
> > +        return;
> > +
> > +    wasAudioSessionInitialized = true;
> > +    if (!WebCore::applicationIsMobileSafari())
> > +        return;
> > +
> > +    AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
> > +}
> > +#endif
> 
> Why do we only want to do this on iOS (and only in MobileSafari)?
> 
AudioSession only has category support on iOS. We only set the category in MobileSafari because apps using a UIWebView may need to use another category, and can do so with the UIWebView.

> > Source/WebCore/html/HTMLMediaSession.cpp:71
> > +#if PLATFORM(IOS)
> > +    initializeAudioSession();
> > +#endif
> 
> I would rather we always call this, and have it do nothing on platforms that don't need it.
>
OK, I will fix this in a follow-up.
Comment 4 Eric Carlson 2014-01-17 11:34:02 PST
(In reply to comment #3)
> (In reply to comment #2)
> > I would rather we always call this, and have it do nothing on platforms that don't need it.
> >
> OK, I will fix this in a follow-up.

By which I meant  "I will fix this when I check in".
Comment 5 Eric Carlson 2014-01-17 13:33:38 PST
Committed r162221: http://trac.webkit.org/changeset/162221