Closed Bug 533840 Opened 15 years ago Closed 2 years ago

Autoplay media does not pause when removed from the document

Categories

(Core :: Audio/Video: Playback, defect, P2)

1.9.1 Branch
defect

Tracking

()

RESOLVED WONTFIX

People

(Reporter: gauthierm, Unassigned)

References

Details

(Keywords: testcase)

Attachments

(2 files)

According the the HTML5 draft specification, the user-agent should act like the pause() method is called if a media element is removed from the document and the networkState has a value other than NETWORK_EMPTY (0).

When a media element is removed in Firefox and the networkState is NETWORK_LOADING (2) the media keeps buffering, and then starts playing in the background.

See test case at http://labs.silverorange.com/files/mozilla/video-testcase/test-case.html
Component: General → Video/Audio
Keywords: testcase
Product: Firefox → Core
QA Contact: general → video.audio
Hardware: x86 → All
Version: 3.6 Branch → 1.9.1 Branch
I'm interested in working on this bug.
I've got experience in c++ but, i'm new to firefox developpement.
So, i don't know really where to start.
Could someone help me to get in ?
Thanks
The code that gets called when the element is removed from the DOM is at [1].

After a quick look, it seems that the code is correct, but for some reason, |mPaused| is |true|, so we don't call the |Pause| method. We need to understand why |mPaused| it |true| at that point.

The testcase in comment 0 is still valid. What should happen is that it should not produce any sound (that is, the element should be paused when removed from the DOM).

[1]: http://mxr.mozilla.org/mozilla-central/source/content/html/content/src/HTMLMediaElement.cpp#2277
Bastien is going to work on that. He is an ENSIMAG [1] student, and is trying to fix bugs in open-source software for a school project.

[1]: http://ensimag.grenoble-inp.fr/
Assignee: nobody → bastien42
Attached patch Bug 533840 fix (with a test) (deleted) — Splinter Review
This patch corrects the bug 533840. There is also a test in content/media/test.
Attachment #759728 - Flags: review+
Attachment #759728 - Flags: review+ → review?(paul)
Chris, this is a patch by a french student I was mentoring a couple weeks back.
I cleaned it up and reworked the logic a bit, so I'd rather have someone else to
review it.

What is happening here is that we were starting the playback after the
::UnbindFromTree (using the autoplay logic), whereas per spec, we should have
paused the media.
Attachment #767225 - Flags: review?(cpearce)
Assignee: bastien42 → paul
try push: https://tbpl.mozilla.org/?tree=Try&rev=6ad23e2aeb21
Assignee: paul → bastien42
Comment on attachment 767225 [details] [diff] [review]
Don't start playback when removed from a document and autoplaying.  r=

Review of attachment 767225 [details] [diff] [review]:
-----------------------------------------------------------------

::: content/media/test/test_paused_after_removed.html
@@ +24,5 @@
> +  video.parentNode.removeChild(video);
> +  ok(video.paused, "Media should be paused.");
> +  // wait a bit to check we won't receive the a "play" event.
> +  setTimeout(function() {
> +    manager.finished(video.token);

Please set video.src = ""; to force the decoder to be shut down immediately.

@@ +25,5 @@
> +  ok(video.paused, "Media should be paused.");
> +  // wait a bit to check we won't receive the a "play" event.
> +  setTimeout(function() {
> +    manager.finished(video.token);
> +  }, 5000);

Maybe make the timeout smaller? Over enough runs we'll still catch failures.
Attachment #767225 - Flags: review?(cpearce) → review+
https://hg.mozilla.org/mozilla-central/rev/a4f84868850f
Status: NEW → RESOLVED
Closed: 11 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla25
Depends on: 887421
So loadstart and play are both dispatched asynchronously.
It is possible that when we handle loadstart, the runnable to dispatch play is already in the
event loop and we end up dispatching the event even though the element isn't in document anymore.
That seems to cause bug 887421.
I may back this out in order to get other stuff (which happens to cause the test failure to happen more often) landed.
Rather than back this out, I think that we should change test_paused_after_removed.html to listen for "pause" rather than "play" events, and end the test in the "pause" handler. We can't be sure that the play event will never be in the event queue by the time that "loadstart" fires, so it's the best that we can do I think. That also removes the timeout in the test, making it faster.
It won't work, we don't fire "pause" in this test.
We should fire "pause", shouldn't we?
Per spec, we should fire pause only if we are not paused. And we are paused when removing the element from the document, here (because we remove it right after "loadstart" has fired).
https://hg.mozilla.org/integration/mozilla-inbound/rev/6bd848b916c8
https://hg.mozilla.org/integration/mozilla-inbound/rev/cc7af847469c

I decided to back this out, since I've had enough problems with broken tests.
I'll look at this once I know bug 789919 sticks in.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Flags: in-testsuite+
Target Milestone: mozilla25 → ---
Attachment #759728 - Flags: review?(paul)
(In reply to Olli Pettay [:smaug] from comment #17)
> I decided to back this out, since I've had enough problems with broken tests.
> I'll look at this once I know bug 789919 sticks in.

I think it stuck :)
Smaug -- noticed this when I was doing bug clean up.
Component: Audio/Video → Audio/Video: Playback
Flags: needinfo?(bugs)
Comment on attachment 767225 [details] [diff] [review]
Don't start playback when removed from a document and autoplaying.  r=

So I tried to look at it again, but I don't understand
mWasInDocument && IsInDoc(). (Also, I'm not at all familiar with the media code.)

If we are in document, we sure should have mWasInDocument == true.
Also, looks like HTMLMediaElements have now mElementInTreeState.
Should that be reused here? It was added in bug 1095438.
Though, it is not clear to me what ELEMENT_INTREE actually means.
document.createElement("div").innerHTML = "<audio>"; will set it, but should it be set only when media element is inserted into document?
Similar with ELEMENT_NOT_INTREE_HAD_INTREE.

Perhaps Benjamin could take a look at this?
(I assume this bug is still valid.)
Flags: needinfo?(bugs) → needinfo?(bechen)
Assignee: bastien42 → bechen
Flags: needinfo?(bechen)
Rank: 15
Priority: -- → P2

The bug assignee didn't login in Bugzilla in the last 7 months.
:jimm, could you have a look please?
For more information, please visit auto_nag documentation.

Assignee: bechen → nobody
Flags: needinfo?(jmathies)
Status: REOPENED → RESOLVED
Closed: 11 years ago2 years ago
Flags: needinfo?(jmathies)
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: