Echo here from => https://stackoverflow.com/questions/63393245/mediastreamtrack-doesnt-play-video-on-htmlvideoelement
I am not sure if this is mediasoup-client specific but the forum helped me so far to learn a lot about producing and consuming video, the last part to make this work is to show the remote video to a consumer and for some reason although it looks fine I can’t seem to get the video play on HTMLVideoElement. Reposting here for the community to help with ideas if possible.
I have the below JavaScript code to set a MediaStreamTrack
to MediaStream
and then as srcObject
to HTMLVideoElement
.
let track = result.data?.track
if (track.kind === 'video' && videoElement.current) {
const videoStream = new MediaStream()
videoStream.addTrack(track)
videoElement.current.srcObject = videoStream
videoElement.current.oncanplay = () => logger.info(`video oncanplay`)
videoElement.current.onplay = () => logger.info(`video onplay`)
videoElement.current.onpause = () => logger.info(`video onpause`)
videoElement.current
.play()
.then(() => logger.info(`video play`))
.catch((error) =>
logger.warn(`videoElem.play() failed: ${error}`))
}
The only logging I see from registered delegate functions is the onplay
, nothing else pretty much is invoked.
The HTMLVideoElement.
<video
ref={videoElement}
controls={false}
autoPlay
playsInline
/>
The MediaStream.
MediaStream {id: "ab29093c-085a-4f12-9590-8af635614cb8", active: true, onaddtrack: null, onremovetrack: null, onactive: null, …}
active: true
id: "ab29093c-085a-4f12-9590-8af635614cb8"
onactive: null
onaddtrack: null
oninactive: null
onremovetrack: null
The MediaStreamTrack.
MediaStreamTrack {kind: "video", id: "8f13425b-c052-491f-a190-a24e2939fbf3", label: "8f13425b-c052-491f-a190-a24e2939fbf3", enabled: true, muted: false, …}
contentHint: ""
enabled: true
id: "8f13425b-c052-491f-a190-a24e2939fbf3"
kind: "video"
label: "8f13425b-c052-491f-a190-a24e2939fbf3"
muted: true
onended: null
onmute: null
onunmute: null
readyState: "live"
Not sure why muted=false
but when I click the arrow details evaluating the object will show muted=true
Doing the same thing for an audio stream track is working fine.
Screenshot from browser logs.