Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CaptureStream adds mediaTracks with delay, we need a callback? #923

Closed
IvRRimum opened this issue Nov 8, 2016 · 3 comments
Closed

CaptureStream adds mediaTracks with delay, we need a callback? #923

IvRRimum opened this issue Nov 8, 2016 · 3 comments

Comments

@IvRRimum
Copy link

IvRRimum commented Nov 8, 2016

When calling video.captureStream() getTracks() returns empty array, but after 1.5 seconds, it returns tracks as expected.

Error produced if no tracks are added: http://stackoverflow.com/questions/40472743/webrtc111-error-domexception-internalerror-cannot-create-an-offer-with-no-lo

Adding this for doc purposes, as others might find this confusing.

Solution:

setInterval(function(){
// We wait till the mediaTracks are added to mediaStream
console.log(stream.getTracks());
// Further actions with the mediaStream
}, 1000);

Thanks!

@alvestrand
Copy link
Contributor

Doesn't the addtrack event fire?

The API is described as a synchronoous interface, so if the tracks aren't present at the beginning, they need to fire the addtrack event when added.

This should probably be a bug on the mediacapture-fromelement spec: https://w3c.github.io/mediacapture-fromelement/

@alvestrand
Copy link
Contributor

Closing as "wrong spec".

@zaidiqbalsoftech
Copy link

zaidiqbalsoftech commented Jun 14, 2022

This is because you are capturing stream before video is played. You need to capture stream after video has started playing to avoid delay in stream tracks.

A better way instead of setTimeout is to use:
1- Use await on video.play() method and capture stream after that.
2- Use 'onplay' event of video element to capture stream when video is played.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants