TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

Property 'getTracks' does not exist on type 'MediaSource'.

Open alysonvilela opened this issue 2 years ago • 3 comments

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

alysonvilela avatar Nov 28 '22 21:11 alysonvilela

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject

The object can be a MediaStream, a MediaSource, a Blob, or a File (which inherits from Blob).

So srcObject is not always a MediaStream.

MartinJohns avatar Nov 28 '22 21:11 MartinJohns

@MartinJohns So it should be always MediaStream on HTMLVideoElement right?

alysonvilela avatar Nov 28 '22 21:11 alysonvilela

Uhm... No. It's not always a MediaStream, so it shouldn't always be one on HTMLVideoElement either.

MartinJohns avatar Nov 28 '22 22:11 MartinJohns