Skip to content

Commit

Permalink
VID-706: Add button to enable sound in live player
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Oct 18, 2023
1 parent 8f419fb commit 3f1ef0e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
3 changes: 3 additions & 0 deletions plugin/live/amd/build/audioswitch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugin/live/amd/build/audioswitch.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions plugin/live/amd/src/audioswitch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Audio control listner
*
* @package videotimeplugin_live
* @module videotimeplugin_live/audioswitch
* @copyright 2023 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Handle click event
*
* @param {Event} e Click event
*/
const handleClick = e => {
const button = e.target.closest('[data-contextid] button[data-audio]');

if (button) {
const action = button.getAttribute('data-audio'),
contextid = button.closest('[data-contextid]').getAttribute('data-contextid');

e.stopPropagation();
e.preventDefault();

document.querySelectorAll('[data-contextid] button[data-audio]').forEach(button => {
if (button.getAttribute('data-audio') === action) {
button.classList.add('hidden');
} else {
button.classList.remove('hidden');
}
});

document.querySelectorAll(`[data-contextid="${contextid}"] audio`).forEach(audio => {
audio.setAttribute('volume', action === 'disable' ? 0 : 1);
audio.muted = (action === 'disable');
});
}
};

export default {
/**
* Add listener
*/
init: function() {
document.removeEventListener('click', handleClick);
document.addEventListener('click', handleClick);
}
};
2 changes: 2 additions & 0 deletions plugin/live/lang/en/videotimeplugin_live.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

defined('MOODLE_INTERNAL') || die();

$string['disableaudio'] = 'Disable audio';
$string['enableaudio'] = 'Enable audio';
$string['enabledeftvideo'] = 'The Video Time live player requires the
admin to install Deft response block and enable video bridging in the
site settings';
Expand Down
8 changes: 6 additions & 2 deletions plugin/live/templates/video_embed.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,26 @@
<audio class="w-100"
id="audio-embed-{{uniqueid}}"
autoplay
controls {{# playsinline }} playsinline {{/ playsinline }}
muted
{{# playsinline }} playsinline {{/ playsinline }}
>
</audio>
<button class="" data-audio="enable">{{# str }} enableaudio, videotimeplugin_live {{/ str }}</button>
<button class="hidden" data-audio="disable">{{# str }} disableaudio, videotimeplugin_live {{/ str }}</button>
</div>
<div class="vimeo-video-description">
{{{video_description}}}
</div>
</div>
{{/ instance }}
{{#js}}
require(['videotimeplugin_live/videotime'], function(VideoTime) {
require(['videotimeplugin_live/audioswitch', 'videotimeplugin_live/videotime'], function(AudioSwitch, VideoTime) {
var v = new VideoTime('video-embed-{{uniqueid}}', {{cmid}}, {{haspro}}, {{interval}}, {{{instance}}});
v.initialize(
{{ contextid }},
'{{ token }}',
{{ peerid }}
);
AudioSwitch.init();
});
{{/js}}

0 comments on commit 3f1ef0e

Please sign in to comment.