Bug 127137 - [iOS] HTMLMediaSession should set AudioSession category
Summary: [iOS] HTMLMediaSession should set AudioSession category
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Eric Carlson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-16 13:08 PST by Eric Carlson
Modified: 2014-01-17 13:33 PST (History)
5 users (show)

See Also:


Attachments
Proposed patch (1.90 KB, patch)
2014-01-16 13:27 PST, Eric Carlson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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