TypeScript
TypeScript 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
}
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.
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.