TypeScript-DOM-lib-generator
TypeScript-DOM-lib-generator copied to clipboard
Property 'getTracks' does not exist on type 'MediaSource'.
According to MDN docs an HTMLMediaElement should have a srcObject that can use a function getTracks()
which can be used to stop a media stream like the link below.
With the current srcObject type this function get an any type, so we need to infer using a as MediaStream to fix it.
// Stop errors
function stopStreamedVideo(videoElem: HTMLMediaElement) {
const stream = videoElem.srcObject as MediaStream
const tracks = stream?.getTracks()
tracks?.forEach((track) => {
track.stop()
})
videoElem.srcObject = null
}
// Show errors
function stopStreamedVideo(videoElem: HTMLMediaElement) {
const stream = videoElem.srcObject
const tracks = stream?.getTracks()
tracks?.forEach((track) => {
track.stop()
})
videoElem.srcObject = null
}
Originally posted by @alysonvilela in https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/306#issuecomment-1329767753
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject
The object can be a
MediaStream
, aMediaSource
, aBlob
, or aFile
(which inherits fromBlob
).
So srcObject
is not always a MediaStream
.
@MartinJohns So it should be always MediaStream on HTMLVideoElement right?
Uhm... No. It's not always a MediaStream
, so it shouldn't always be one on HTMLVideoElement
either.