I'm using the Window's MediaCapture class from a Win8 html/javascript application. When I stop displaying the preview video in a <video />
tag, I figured I'd need to use the StopPreviewAsync
method to end the preview stream. However, the MediaCapture.StopPreviewAsync method doesn't appear to be available from javascript. It's not documented on MSDN for javascript and attempting to call it results in a runtime error:
Object doesn't support property or method 'stopPreviewAsync'.
Is it not necessary to close the stream when using a MediaCapture
instance from javascript? Why does it exist for only C#/C++/VB?
I ended up getting an answer from the Microsoft team that develops the Media Capture API. There is no guaranteed method of closing the stream and giving up the camera. The only option is to remove all references to the stream and then call CollectGarbage()
. The camera will be released whenever the associated memory is reclaimed. Apparently a more explicit method of releasing the camera will be coming at some point for Windows 8.1.