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

[Feature Request] Set 'autoplay' property when creating the video element #174

Closed
Techn1c4l opened this issue Apr 10, 2021 · 8 comments
Closed

Comments

@Techn1c4l
Copy link

Techn1c4l commented Apr 10, 2021

I faced the issue when using the Html5Qrcode class - the camera stream won't play automatically on an Android Cordova app. Only the ugly grey placeholder would appear.

At first, I wrote the code to set the setMediaPlaybackRequiresUserGesture to false for the system WebView component which is used by Cordova:

WebView webView = (WebView) appView.getEngine().getView();
WebSettings webSettings = webView.getSettings();
webSettings.setMediaPlaybackRequiresUserGesture(false);

The problem still persisted. I had to modify the _createVideoElement method in the html5-qrcode.js file by adding the code which sets the autoplay property of the videoElement to true:

_createVideoElement(width) {
        const videoElement = document.createElement('video');
        videoElement.style.width = `${width}px`;
        videoElement.muted = true;
        videoElement.playsInline = true;
	videoElement.autoplay = true;
        return videoElement;
    }

This solution worked fine. Please consider implementing this feature.

@mebjas
Copy link
Owner

mebjas commented Apr 15, 2021

Thanks for reporting the issue and suggesting a fix, will try it out and send a PR thanks!

@mebjas
Copy link
Owner

mebjas commented May 28, 2021

@Techn1c4l Can you confirm if this is still needed to run the video stream successfully on Cordova app?

@mebjas
Copy link
Owner

mebjas commented Jun 27, 2021

Closing for now, please reopen if issue still exists!

@mebjas mebjas closed this as completed Jun 27, 2021
@tectiv3
Copy link

tectiv3 commented Feb 21, 2022

This issue is still exists on samsung phones.

NotAllowedError: play() failed because the user didn't interact with the document first.

Screen Shot 2022-02-21 at 13 49 38

@tectiv3
Copy link

tectiv3 commented Nov 24, 2022

Still happening.

Screen Shot 2022-11-24 at 13 51 22

@mebjas
Copy link
Owner

mebjas commented Nov 25, 2022 via email

@tectiv3
Copy link

tectiv3 commented Nov 25, 2022

Everything is on the screenshot from sentry:)

@rgagne
Copy link

rgagne commented May 16, 2023

Had the same problem and the fix suggested by @Techn1c4l above takes care of it.

I have not exhaustively tested on all platforms but resolves Android and works fine on MacOS Chrome with the change. Could be related to https://stackoverflow.com/questions/67038895/htmlvideoelement-wont-autoplay-on-a-cordova-android-app.

Adding autoplay to createVideoElement in core-impl.ts

private createVideoElement(width: number): HTMLVideoElement {
        const videoElement = document.createElement("video");
        videoElement.style.width = `${width}px`;
        videoElement.style.display = "block";
        videoElement.muted = true;
        videoElement.setAttribute("muted", "true");
        (<any>videoElement).playsInline = true;
        (<any>videoElement).autoplay = true;
        videoElement.setAttribute("autoplay", "true");
        return videoElement;
    }

Other related ticket #198

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

No branches or pull requests

4 participants