I am trying to develop a plugin in which I need to access the webcam. but I am not able to open the webcam if I do inspect I am getting accessibility and unable to play media. Does moodle need any additional settings?
I have a simple view.php
require_once (__DIR__.'/../../config.php'); $PAGE->requires->js_call_amd('local_webcam/camera'); $PAGE->set_title("View Webcam here"); $PAGE->set_context(\context_system::instance()); $PAGE->set_url(new moodle_url('/local/webcam/view.php')); $templatecontext = (object)[ "webcam" => 'Preview of Webcam' ]; echo $OUTPUT->header(); echo $OUTPUT->render_from_template('local_webcam/view', $templatecontext); echo $OUTPUT->footer();
2.Template file
`
<input type="button" class="btn btn-light" id="viewbutton" value="CLick me">
<video id="liveview" height="480" width="640" autoplay muted></video>`
My javascript file
define(['jquery'], function($) { $('#viewbutton').click(function() { let liveview = $("#liveview"); // eslint-disable-next-line promise/catch-or-return navigator.mediaDevices.getUserMedia({video: {width: 640, height: 480}, audio: false}).then((stream) =>{ liveview.srcObject = stream; }); });
});`
This is the error I am getting. If I try to run in normal file. outside of moodle. It is working.