diff --git a/filter.php b/filter.php index 68d69ad..b2a2d36 100644 --- a/filter.php +++ b/filter.php @@ -33,6 +33,7 @@ class filter_vdocipher extends moodle_text_filter private static $playerTheme; private static $width; private static $height; + private static $speedOptions; public function filter($text, array $options = array()) { self::$csk = get_config('filter_vdocipher', 'csk'); @@ -47,6 +48,7 @@ public function filter($text, array $options = array()) self::$playerTheme = '9ae8bbe8dd964ddc9bdb932cca1cb59a'; } self::$watermark = get_config('filter_vdocipher', 'watermark'); + self::$speedOptions = get_config('filter_vdocipher', 'speedOptions'); if (strpos($text, '[vdo ') === false) { return $text; } @@ -145,10 +147,37 @@ function eval_date($matches) }); EOF; + } + if (self::validSpeed()) { + $speedOptions = self::$speedOptions; + $output .= << + function onVdoCipherAPIReady() { + var allVideos = vdo.getObjects(); + var video_ = allVideos[allVideos.length - 1]; + video_.addEventListener('load', function () { + video_.availablePlaybackRates = [$speedOptions] + }); + } + +EOF; + } return $output; }, $text); } + + private static function validSpeed() { + if (!self::$speedOptions) return false; + $speeds = explode(',', self::$speedOptions); + foreach ($speeds as $speed) { + if (!is_numeric($speed)) return false; + $floatSpeed = floatval($speed); + if ($floatSpeed < 0.2 || $floatSpeed > 2.5) return false; + } + return true; + } + private function vdo_otp($video, $otp_post_array = []) { $client_key = self::$csk; diff --git a/lang/en/filter_vdocipher.php b/lang/en/filter_vdocipher.php index 2d9a9e1..11c6622 100644 --- a/lang/en/filter_vdocipher.php +++ b/lang/en/filter_vdocipher.php @@ -34,7 +34,10 @@ $string['playerVersion_desc'] = 'Setting to 1.x uses the latest and recommended video player version'; $string['playerTheme'] = 'Player Theme'; -$string['playerTheme_desc'] = 'This is the player theme. Available player themes are listed in the Custom player skin page'; +$string['playerTheme_desc'] = 'This is the player theme.'; + +$string['speedOptions'] = 'Speed options'; +$string['speedOptions_desc'] = 'Change the player menu for speed. Accepts comma-separated string with each value between 0.2 to 2.5. Can cause error if invalid.'; $string['watermark'] = 'Watermark JSON'; $string['watermark_desc'] = '(Optional) Watermark to be applied to the videos. For details on writing the annotation code check this out. '; diff --git a/settings.php b/settings.php index 91170ff..c9f3935 100644 --- a/settings.php +++ b/settings.php @@ -26,9 +26,7 @@ 'filter_vdocipher/csk', get_string('csk', 'filter_vdocipher'), get_string('csk_desc', 'filter_vdocipher'), - null, - PARAM_NOTAGS, - 64 + null )); $settings->add(new admin_setting_configtext( @@ -58,14 +56,22 @@ 32 )); +$settings->add(new admin_setting_configtext( + 'filter_vdocipher/speedOptions', + get_string('speedOptions', 'filter_vdocipher'), + get_string('speedOptions_desc', 'filter_vdocipher'), + '', + PARAM_NOTAGS, + 32 +)); + $settings->add(new admin_setting_configtext( 'filter_vdocipher/playerTheme', get_string('playerTheme', 'filter_vdocipher'), get_string('playerTheme_desc', 'filter_vdocipher'), '9ae8bbe8dd964ddc9bdb932cca1cb59a', PARAM_NOTAGS, - 64, - 2 + 64 )); $settings->add(new admin_setting_configtextarea(