[mediacapture-main] When is a MediaStream playing? (#615)

jan-ivar has just created a new issue for https://github.com/w3c/mediacapture-main:

== When is a MediaStream playing? ==
Consider setting an empty stream on an element and adding a track later. When is it playing?
```js
video.srcObject = new MediaStream();
video.play();                    // video.currentTime = 0
await wait(5000);                // video.currentTime = ?
video.srcObject.addTrack(track); // video.currentTime = ?
```

[mediacapture-main says](https://w3c.github.io/mediacapture-main/#mediastreams-in-media-elements): *"A MediaStream is not preloadable or seekable and represents a simple, potentially infinite, linear media timeline. The timeline starts at 0 and increments linearly in real time as long as the* ***MediaStream is playing.*** *The timeline does not increment when the playout of the MediaStream is paused."*

What definition of *"playing"* is used? We probably mean [potentially playing](https://html.spec.whatwg.org/multipage/media.html#potentially-playing), a definition the element uses e.g. [here](https://html.spec.whatwg.org/multipage/media.html#media-playback): *"When a media element is potentially playing ... its current playback position must increase monotonically"*.

I wrote a [fiddle](https://jsfiddle.net/jib1/pb0uwa6s/) to check what browsers do in this case, and it's a bit all over the map:

* Firefox 68 fires 1st `timeupdate` w/time `~0.01` on empty stream set.
* Firefox 70 fires 1st `timeupdate` w/time `~0.01` when track is added to stream later.
* Chrome 76 fires 1st `timeupdate` w/time `~177281` when track is added to stream later.¹
* Chrome 78 same
* Safari 12 plays black, Fires 1st and only `timeupdate` w/time `0` when track is added.
* Safari 13 plays black. No events.
* Edge 44 `Error: Unexpected call to method or property access on empty stream set.`

Using the [potentially playing](https://html.spec.whatwg.org/multipage/media.html#potentially-playing) definition would mean Firefox 70 and Chrome¹ have the correct behavior, I think. That definition relies on `readyState` being `HAVE_ENOUGH_DATA` which I observe being the case when `timeupdate` fires.

---
<sub>1. Chrome's `currentTime` jump from 0 to thousands of seconds seems like a bug orthogonal to this spec question.</sub>

Please view or discuss this issue at https://github.com/w3c/mediacapture-main/issues/615 using your GitHub account

Received on Wednesday, 28 August 2019 22:57:32 UTC