New issue
Advanced search Search tips

Issue 592158 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Aug 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug



Sign in to add a comment

Calling video.play() before setting src is not reliable

Project Member Reported by sande...@chromium.org, Mar 5 2016

Issue description

This JS reliably results in playing video:

  video.play();
  video.src = "bbb.mp4";

This JS reliably loads but does not play the video:

  video.play();
  window.setTimeout(() => video.src = "bbb.mp4", 0);

(Similar results can be obtained using promises.)

The difference appears to be due to interleaved task scheduling, but I have not fully investigated.

I've attached my test files along with the Media log channel output, but reproduction is trivial.
 
set_src_immediately.html
181 bytes View Download
set_src_after_timeout.html
209 bytes View Download
set_src_immediately.blink_log.txt
2.2 KB View Download
set_src_after_timeout.blink_log.txt
1.9 KB View Download

Comment 1 by phil...@opera.com, Mar 7 2016

Thanks for these test cases! However, I'm seeing the opposite behavior, the "immediately" case doesn't play and the "after timeout" one does. Firefox Nightly does the same. Did you paste the wrong thing in the description, or is that the behavior you're seeing?

I added some console.log'ing of networkState, readyState and paused at the various steps to investigate.

Per spec, calling play() should invoke the "resource selection algorithm" if networkState == NETWORK_EMPTY, which is going to be the case here. That immediately sets networkState to NETWORK_NO_SOURCE and should "await a stable state" before looking at the src attribute. What the implementation actually does is to set a timer, which is equivalent to posting a task rather than a microtask. That's suspect, but doesn't seem to be to blame here.

Also per spec, setting the src attribute is supposed to invoke the "media element load algorithm", which resets the paused state, but ONLY if networkState != NETWORK_EMPTY. The implementation doesn't quite do this, but the relevant bits in HTMLMediaElement::prepareForLoad() are run with the correct timing. (The continuation is wrong, see issue 592396.)

So, what should happen is that in the "immediately" case, networkState is NETWORK_NO_SOURCE when the src attribute is called, so the paused attribute is reset. In the "after timeout" case the resource selection algorithm will already have run and failed to find a source an returned to NETWORK_EMPTY. That's why setting the src doesn't reset the paused state.

Even though per spec, this is somewhat confusing. You should always get reliable behavior by calling play() after setting the src.

I'm wondering if maybe the spec should change to always reset the paused state, but that would mean that calling play() before setting src never works, instead of sometimes working. Would that be an improvement?
You are correct, the first version does not play but the second does. It looks like I also switched the log names, which may have actually been the original source of confusion.

While it makes far more sense to set src and then call play(), the fact that some of the Chromium browser_tests are relying on the opposite is not a good sign for the compatibility of a change.

Comment 3 by phil...@opera.com, Mar 14 2016

Status: WontFix (was: Untriaged)
I've filed https://github.com/whatwg/html/issues/869, will close this as WontFix until there's a spec change. I couldn't find your GitHub account, can you add yourself if you're interested?

You're right that changing this behavior has some risk, I guess we'll have to add use counters if want to try it.

Comment 4 by sshru...@google.com, Mar 21 2016

Components: -Blink>Video Blink>Media>Video
Renaming Blink>Video to Blink>Media>Video for better characterization
Cc: -phil...@opera.com foolip@chromium.org mlamouri@chromium.org
Components: -Blink>Media>Video Blink>Media
Status: Available (was: WontFix)
Reopening this because I'm looking into the issue. I can't actually get the video to play after setting the src. Are you all still able to reproduce this?
I can still reproduce this exactly on 54.0.2810.2, (noting that the descriptions in the first post are swapped. (It's the second one that plays and the first one that fails.)
Cc: -mlamouri@chromium.org
Owner: mlamouri@chromium.org
Status: Started (was: Available)
Project Member

Comment 8 by bugdroid1@chromium.org, Aug 4 2016

Labels: M-54
Status: Fixed (was: Started)

Sign in to add a comment