Close GetCapture Video Stream

Using getCapture to show web cam input.... I want to clean up the sketch after I am done, how do I close the stream?

Answers

  • edited June 2016
  • Yeah, I expected stop() on the returned MediaElement would do it, that's the first thing I tried. No luck, though.

    I will try remove () on it as well.

  • Answer ✓

    Okay, I got it. Looking through the sources for the p5 dom project I discovered that createCapture takes an optional callback that has a stream object as an argument. getTracks()[0] on the stream should return the current video feed, which can then be closed with stop(). So in my case something resembling the following does the trick (from within an object I have created):

    var stream;

    this.setup = function () { capture = p.createCapture(p.VIDEO, function(streamRef) { stream = streamRef; }); }

    this.onDeinit = function() { stream.getTracks()[0].stop(); }

Sign In or Register to comment.