Closed Bug 1334825 Opened 7 years ago Closed 7 years ago

Audio playback on BBC iPlayer stops shortly after Firefox enters into background

Categories

(Firefox for Android Graveyard :: Audio/Video, defect, P1)

All
Android
defect

Tracking

(Not tracked)

VERIFIED DUPLICATE of bug 1336484

People

(Reporter: JanH, Unassigned)

References

Details

Attachments

(3 obsolete files)

STR:
1. Go to bbc.co.uk/radio4
2. Click on "Listen live"
3. Switch to your home screen/a different app/the task switcher/turn your screen off or do anything else that leads to Firefox being in the background as far as Android is concerned [1]. Actually in fact even just switching to some other tab is enough to trigger this.

Expected:
Audio playback continues unless memory pressure gets so severe that Android decides to kill Firefox for good to make way for some other app.

Actual:
After some varying amount of time (usually less than a minute), audio playback stops, however this is *not* because Firefox has been killed - when you bring it back into the foreground, it runs immediately and audio playback eventually resumes after a few seconds (more or less exactly from where it stopped, I think). Likewise, if you've just switched to some different tab, the iPlayer tab definitively *wasn't* zombified.

My phone: Moto G4 Play, Android 6.0.1, today's Nightly
Turning off battery optimisations for Nightly doesn't seem to make any difference here.

Other things to note:
The audio playback icon in the tab list appears and there are no AUDIO_PLAYING_CHANGE messages relating to the audio icon turning on/off while playback stops in background and resumes afterwards.
The new media control notification however is not visible.

Unlike Youtube in bug 1324282, I don't think the BBC has any motivation to prevent background playback here and besides, with the current Chrome (release) version, things work fine and Chrome is also showing its media control notification in this case.
Blake, Anthony, can you folks look into this?
Flags: needinfo?(bwu)
Flags: needinfo?(ajones)
See Also: → 1337030
Flags: needinfo?(ajones) → needinfo?(jolin)
It seems the site uses DASH-IF player [1] and this problem is also reproducible with their sample player [2].
That should make debugging easier because the source is not obfuscated/minified.

[1] https://github.com/Dash-Industry-Forum/dash.js
[2] http://mediapm.edgesuite.net/dash/public/nightly/samples/dash-if-reference-player/index.html
Flags: needinfo?(jolin)
Flags: needinfo?(bwu)
Looks like dash.js uses setTimeout() to schedule data fetching [1]. Since Fennec throttles timeouts in inactive tabs to be 15mins [1] (versus 1s on Desktops), the player run out of data and stopped. :(
When I set 'dom.min_background_timeout_value' to 1000, YouTube, BBC Radio, and DASH-IF player all play fine in the background.

Bug 1181073 and 1291741 relaxes the throttling for WebAudio, I suppose we should do so for media elements.

Alastor, do you know if there are something for us to check whether media element is playing in a tab?


[1] http://searchfox.org/mozilla-central/source/mobile/android/app/mobile.js#719
Flags: needinfo?(alwu)
After discussed with John, although now we didn't have the way to know whether there is any playing media element, we found some possible way to achieve that. 
We can do the way like AudioContext and increase/decrease the count in [1]. 

[1] http://searchfox.org/mozilla-central/rev/672c83ed65da286b68be1d02799c35fdd14d0134/dom/html/HTMLMediaElement.cpp#854
Flags: needinfo?(alwu)
Priority: -- → P1
I believe this is a dupe of what ehsan is working.
Flags: needinfo?(ehsan)
Found the bug.
Status: NEW → RESOLVED
Closed: 7 years ago
Flags: needinfo?(ehsan)
Resolution: --- → DUPLICATE
Comment on attachment 8835909 [details]
Bug 1334825 - part 1: relax setTimeout throttling in background tabs when audio is playing by media element.

Sorry, I think we should favor the approach in bug 1336484 because it uses the same "any audio" detection that our tab indicator uses.
Attachment #8835909 - Flags: review?(bkelly)
Attachment #8835910 - Flags: review?(alwu)
Comment on attachment 8835911 [details]
Bug 1334825 - part 3: test case.

Can you move this test to bug 1336484?
Attachment #8835911 - Flags: review?(bkelly) → review+
Oops, sorry for stepping on your toes!

(In reply to Ben Kelly [:bkelly] from comment #11)
> Comment on attachment 8835911 [details]
> Bug 1334825 - part 3: test case.
> 
> Can you move this test to bug 1336484?

That bug actually landed with a test, but it's lacking the audio pause part, which I think would be a nice addition.  I think we want to add an array of functions per each URL with custom code to pause each kind of page we're testing (see the other tests that use the helper files for how to do that).  Can you please make a patch to add this to the test there?  Thank you!
Attachment #8835909 - Attachment is obsolete: true
Attachment #8835910 - Attachment is obsolete: true
Attachment #8835911 - Attachment is obsolete: true
Background playback now working beautifully.
Status: RESOLVED → VERIFIED
(In reply to :Ehsan Akhgari from comment #12)
> Oops, sorry for stepping on your toes!

 Accepted. :P

> 
> That bug actually landed with a test, but it's lacking the audio pause part,
> which I think would be a nice addition.  I think we want to add an array of
> functions per each URL with custom code to pause each kind of page we're
> testing (see the other tests that use the helper files for how to do that). 
> Can you please make a patch to add this to the test there?  Thank you!

 No idea what to look for, I'm afraid. Could you please help name one test that does it? Thanks a lot!
Flags: needinfo?(ehsan)
Sure, this is the test that I added: <https://hg.mozilla.org/mozilla-central/diff/77313ca8fd71/dom/base/test/browser_timeout_throttling_with_audio_playback.js>

You'll note that the test runs over 4 test URLs.  For example, for file_audioLoop.html, in order to implement the pausing you can use the HTMLMediaElement on the <audio> element in that file directly.  For a more sophisticated test URL such as file_pluginAudio.html you can search for the name of the test file to find the other test this helper file is used for, and mute the plugin audio similar to this code for example: <http://searchfox.org/mozilla-central/rev/d3307f19d5dac31d7d36fc206b00b686de82eee4/dom/base/test/test_pluginAudioNotification.html#80>.  file_webaudioLoop.html provides a similar suspendAC() function as used here: <http://searchfox.org/mozilla-central/rev/d3307f19d5dac31d7d36fc206b00b686de82eee4/dom/base/test/test_webaudioNotification.html#46>
Flags: needinfo?(ehsan)
Ehsan, thanks a lot for your help. Filed bug 1339324 for this.
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: