auduno / headtrackr

Javascript library for headtracking via webcam and WebRTC/getUserMedia
3.69k stars 504 forks source link

No possibility to stop mediastream opened by headtrackr.init() #24

Closed auduno closed 9 years ago

auduno commented 10 years ago

It is not possible to close the getUserMedia mediastream opened by headtrackr on init(), since the mediastream pointer is discarded after initialization. The solution is to not discard the pointer and possibly add a method to close/stop the stream.

ricricucit commented 10 years ago

+1 for this. Is it also possible to maybe add Addy Osmani's GetUserMedia shim (https://github.com/addyosmani/getUserMedia.js) ?

auduno commented 10 years ago

I don't think I'll add the shim in headtrackr, but I was thinking of creating an option for providing your own videoElement "as is", i.e. without setting up getUserMedia, so you could then set up video with the getUserMedia shim first and provide the videoelement to headtrackr. I'll have to look at the complications wrt the rest of the code of doing this, though.

ricricucit commented 10 years ago

Fair enough. It might even be a better idea. thanks!

auduno commented 10 years ago

Alright, I've now added a function to stop the mediastream, so you can now call

htracker.stopStream()

on your instance of headtrackr to stop streaming from the webcam. You can also get the mediastream object from the htracker.stream property. I've also added the boolean parameter setupVideo to init(), so you have the possibility to use the videoElement "as is" by calling:

htracker.init(videoElement, canvasElement, false)

In the case you try to use the getUserMedia shim mentioned, and it's falling back to flash, I think you have to copy the video from the flash element onto a canvas (every 1/24 second or so) and pass that on to init() as the video element instead.

ricricucit commented 10 years ago

brilliant. thanks.

auduno commented 10 years ago

Do you stop the headtracker (i.e. call htracker.stop() ) as well when you stop the stream? Or do you just call htracker.stopStream() ?

auduno commented 10 years ago

huh, that's weird. It works for me. Do you see any error messages in console?

auduno commented 10 years ago

I can't reproduce this. Could you share the code you're using or a mockup on dropbox or somewhere?

abaziz commented 10 years ago

@auduno this is working fine at our end now, the error in the previous message by Raees ("Cannot read property 'getTrackingObject' of undefined") was due to some issue in our code. Many thanks for adding this functionality.