cordova-plugin-media-capture icon indicating copy to clipboard operation
cordova-plugin-media-capture copied to clipboard

Image capture not working on Chrome browser on PC

Open baibhavprdn opened this issue 6 years ago • 3 comments

Image capture isn't working on Chrome browser

Problem: The browser does not load the preview as expected

I tested this on android (works beautifully), Edge browser which also shows the preview div with the capture preview option.

What I get: Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided. is thrown in the console

Information

I'm trying to include the media capture plugin in a cordova app I've been working on. However I've failed to implement it in the browser for even simple applications.

I searched around in stackoverflow and answers indicate that createObjectURL is supposed to be passed either Blob, File or MediaSources and not raw data but I'm unsure what exactly I need to do to get the plugin working for chrome.

I'm using all latest versions of chrome, cordova.

baibhavprdn avatar Oct 11 '19 06:10 baibhavprdn

Are you able to provide the stacktrace for the error? Perhaps breakpointing to inspect the kind of object that is being tried to be fed in. I think this information will be valuable to not only pinpointing the source but also providing some insight why it's receiving some unexpected type. Thanks.

breautek avatar Oct 11 '19 12:10 breautek

Hey breautek here's the stacktrace for the error:

The error on console is: Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided. at CaptureProxy.js:120

in CaptureProxy.js line 120 that.preview.src = URL.createObjectURL(previewStream);

the previewSteram is being passed a MediaStream. I modified the line with the change: that.preview.srcObject = previewStream; which lets me access the video preview but throws another error when I try to capture the image. Uncaught TypeError: this._previewStream.stop is not a function at CameraUI.destroyPreview (CaptureProxy.js:135) at CaptureProxy.js:188 at HTMLVideoElement.preview.onclick (CaptureProxy.js:109)

Thanks again.

EDIT: After looking into it, I found out that the stop() function for MediaStreams is also deprecated. A workaround for my personal use was using the getVideotracks() function for MediaStreams then using stop() to every individual elements in the array. var track = this._previewStream.getVideoTracks()[0]; // my array only contains a single element track.stop();

For anybody else who's also trying to get the plugin working on browser.

baibhavprdn avatar Oct 14 '19 05:10 baibhavprdn

Sorry I closed the earlier PR and created a new one as I mistakenly created the first PR from my master branch and I didn't intend to do that

onlinesid avatar Apr 10 '20 21:04 onlinesid