Android-SmartWebView icon indicating copy to clipboard operation
Android-SmartWebView copied to clipboard

HTML5 video not working: permission denied

Open esiokugbechoice opened this issue 3 years ago • 3 comments

I am using an HTML5 QR code reader https://github.com/mebjas/html5-qrcode. everything works fine on chrome, but I get the following error when i try from the webview

Please help...

esiokugbechoice avatar May 25 '22 00:05 esiokugbechoice

The camera's permission is disabled, that's why you are getting this error. Simply follow the code given below, the camera will start working as well as your scanner which depends on it.

Under MainActivity.Java file / asw_view.SetwebChromeClient. Post this code

@Nullable
			public Bitmap getDefaultVideoPoster() {
				return Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
			}
			@Override
			public void onPermissionRequest(@NotNull final PermissionRequest request) {
								final String[] requestedResources = request.getResources();
				for (String r : requestedResources) {
					if (r.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) {
						request.grant(new String[]{PermissionRequest.RESOURCE_VIDEO_CAPTURE});
						break;
					}
					if (r.equals(PermissionRequest.RESOURCE_AUDIO_CAPTURE)) {
						request.grant(new String[] { PermissionRequest.RESOURCE_AUDIO_CAPTURE});
						break;
					}
				}
			}

Add the line under websettings webSettings.setMediaPlaybackRequiresUserGesture(false);

And make sure record_audio and camera permissions are granted in android manifest xml.

husaindevelop avatar Jun 12 '22 15:06 husaindevelop

i got the same problem and @husaindevelop, i put your code but give me error when i build app.

error: cannot find symbol public void onPermissionRequest(@NotNull final PermissionRequest request) { ^ symbol: class PermissionRequest

@mgks any idea?

Macof08 avatar Apr 11 '23 20:04 Macof08

replace @NotNull with @Nullable also import import androidx.annotation.NonNull; import org.jetbrains.annotations.Nullable;

frogsuite avatar Feb 10 '24 16:02 frogsuite