Open bc-lee opened 1 month ago
I think you should probably look at the event. The code above is looking at the state of the stream.
stream.onaddtrack = (ev) => { console.log('onAddTrack kind: '+ev.track.kind );
I would agree the spec can be clearer on this.
I think the question boils down to whether the events fire sync or async in the text:
If the selected VideoTrack or enabled AudioTracks for the media element change, a addtrack event with a new MediaStreamTrack is generated for each track that was not previously selected or enabled; and a removetrack events is generated for each track that ceases to be selected or enabled. A MediaStreamTrack MUST end prior to being removed from the MediaStream.
I'll also note that the addtrack
event on AudioTrackList
and VideoTrackList
in the media element spec is fired sync, while the change
event on the same objects is fired async.
Consider the following code:
The test video file test-av-384k-44100Hz-1ch-320x240-30fps-10kfr.webm has both audio and video tracks. This code is almost identical to the one in the web platform test.
Below are the logs from the code above:
Chrome 125.0.6422.141:
Firefox 126.0:
In Chrome, the
onaddtrack
is fired twice, however even with the first event, both audio and video tracks are present in the stream. In Firefox, theonaddtrack
is fired twice, but the first event only has the audio track, and the second event has both audio and video tracks.I wonder which behavior is correct. The current web platform test assumes that the behavior in Chrome is correct (it checks only the first event), but it may be an implementation detail of Chrome.