Embed Media Player in Quiz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear members of the Canvas Developer Group
For digital exams, we need a media player that only plays video/audio files only once and prevents any possibility of playing the file a second time, pausing or rewinding the file. After a (quite long) search, we have found a player that does just that. On github we found a code, which only needs to be embedded on a web page (see here: https://github.com/tvandervossen/playonly/blob/main/index.html).
It works perfectly, the code can be embedded on an HTML page without any problems. However, it is not possible to embed the code in a canvas quiz, because there are also a few lines that have to be placed in the page header and we do not have access to the page header in canvas.
The specific question now are:
Do somebody knows a way to embed this code in a canvas quiz (i.e. classic quiz)? Is there a way to do it without the header definitions? Or is there a possibility in Canvas to add this code in the page header somehow?
Due to our very (!) limited coding skills we do need help from this great community...
Many thanks in advance for your support and best regards
Samuel
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah, I assumed it was an online test that the students would be taking off campus - but then it seems that the solution you found is good! All you gotta do is take this HTML snippet:
<p><video class="exam-video" style="width: 100%; height: 100%;" src="INSERT-LINK" controls="controls"></video></p>
And insert it into the quiz question (using the HTML editor). Replace where it says "INSERT-LINK" with the link to the video you want to play - retain the "" around the link. This has to be a direct link to the video and not something an embed link from YouTube or Vimeo.
This is a paragraph with a video in it, scaling 100% meaning it will scale to the max size of the quiz question window (and it will respond if the window is resized). It has a special class called "exam-video" which we will be using to target it's video controls for removal. We handle this with JavaScript, so you will need to upload a JavaScript file in the Canvas account themes. This is the JS you need:
if (document.getElementsByClassName("exam-video") != null){ const exam_video = document.querySelector(".exam-video") exam_video.addEventListener("play", (event) => { exam_video.removeAttribute("controls"); }); }
This works a little different than the GitHub project you posted, issue being that Canvas doesn't allow inline-JavaScript in the Rich Content Editor and it will be erased upon saving the content. But basically, this little script checks - every time a page on the course account is loaded - if there's any elements on the page with the "exam-video" class and if true, it adds an event to the video that removes the video controls once the video plays.
You can get both the HTML and the JS file here: https://github.com/MichaelMarboe/remove_vidcontrols
Then, go into your Canvas instance and open the sub-account that has the course with the exam quiz in it. Select Themes on the left-side menu, open your current theme, select Upload in the top left corner, find JavaScript and select the JavaScript file on your computer. NB: If there's already a JavaScript file here, you already have custom JavaScript and you will need to make a file that has both this code and mine (put it in the end of the file using something like Sublime Text to edit it). Hit Preview, Save and then Apply and you should be up and running. 🙂
NB: This won't work on more than the first exam-video per page load. Also, do some tests once it's up and running - I only tested it in a single question in a classic quiz (not the New Quizzes but it should work the same).
Edit: I only tested this in Firefox. The script will use whatever standard, basic video controls the browser has (and they can vary a bit) but if the special lockdown browser you're using doesn't have basic video controls in it, this may not work at all.