diff --git a/filter/mediaplugin/filter.php b/filter/mediaplugin/filter.php
index 9e4ed55f600..e98f6d9d16e 100644
--- a/filter/mediaplugin/filter.php
+++ b/filter/mediaplugin/filter.php
@@ -43,6 +43,24 @@ class filter_mediaplugin extends moodle_text_filter {
/** @var bool True if currently filtering trusted text */
private $trusted;
+ /**
+ * Setup page with filter requirements and other prepare stuff.
+ *
+ * @param moodle_page $page The page we are going to add requirements to.
+ * @param context $context The context which contents are going to be filtered.
+ */
+ public function setup($page, $context) {
+ // This only requires execution once per request.
+ static $jsinitialised = false;
+ if ($jsinitialised) {
+ return;
+ }
+ $jsinitialised = true;
+
+ $mediamanager = core_media_manager::instance();
+ $mediamanager->setup($page);
+ }
+
public function filter($text, array $options = array()) {
global $CFG, $PAGE;
diff --git a/media/classes/manager.php b/media/classes/manager.php
index 40e7777a2ec..e502d5f7bea 100644
--- a/media/classes/manager.php
+++ b/media/classes/manager.php
@@ -109,6 +109,20 @@ class core_media_manager {
return self::$instance;
}
+ /**
+ * Setup page requirements.
+ *
+ * This should must only be called once per page request.
+ *
+ * @param moodle_page $page The page we are going to add requirements to.
+ */
+ public function setup($page) {
+ $players = $this->get_players();
+ foreach ($players as $player) {
+ $player->setup($page);
+ }
+ }
+
/**
* Resets cached singleton instance. To be used after $CFG->media_plugins_sortorder is modified
*/
diff --git a/media/classes/player.php b/media/classes/player.php
index f7d50ada966..55cd8e35dd9 100644
--- a/media/classes/player.php
+++ b/media/classes/player.php
@@ -253,4 +253,15 @@ abstract class core_media_player {
$height = $CFG->media_default_height;
}
}
+
+ /**
+ * Setup page requirements.
+ *
+ * @param moodle_page $page The page we are going to add requirements to.
+ * @since Moodle 3.2
+ */
+ public function setup($page) {
+ // Override is need be.
+ }
+
}
diff --git a/media/player/videojs/amd/src/loader.js b/media/player/videojs/amd/src/loader.js
new file mode 100644
index 00000000000..c4a5f7cd426
--- /dev/null
+++ b/media/player/videojs/amd/src/loader.js
@@ -0,0 +1,56 @@
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see .
+
+/**
+ * Video JS loader.
+ *
+ * This takes care of applying the filter on content which was dynamically loaded.
+ *
+ * @package media_videojs
+ * @copyright 2016 Frédéric Massart - FMCorz.net
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+define(['jquery', 'media_videojs/video'], function($, videojs) {
+
+ /**
+ * Set-up.
+ *
+ * Adds the listener for the event to then notify video.js.
+ */
+ var setUp = function() {
+ $(document).on(M.core.event.FILTER_CONTENT_UPDATED, notifyVideoJS);
+ };
+
+ /**
+ * Notify video.js of new nodes.
+ *
+ * @param {Event} e The event.
+ * @param {NodeList} nodes List of new nodes.
+ */
+ var notifyVideoJS = function(e, nodes) {
+ nodes.find('.mediaplugin_videojs audio, .mediaplugin_videojs video')
+ .each(function() {
+ var id = $(this).attr('id'),
+ config = $(this).data('setup');
+
+ videojs(id, config);
+ });
+ };
+
+ return {
+ setUp: setUp
+ };
+
+});
diff --git a/media/player/videojs/classes/plugin.php b/media/player/videojs/classes/plugin.php
index b9e0d2dd721..00ef6de2b0d 100644
--- a/media/player/videojs/classes/plugin.php
+++ b/media/player/videojs/classes/plugin.php
@@ -99,10 +99,7 @@ class media_videojs_plugin extends core_media_player_native {
$title = $this->get_name($name, $urls);
$title = preg_replace(['/&/', '/>/', '/</'], ['&', '>', '<'], $title);
- // Ensure JS is loaded. This will also load language strings and populate $this->language with the current language.
- $this->load_amd_module();
if ($this->youtube) {
- $this->load_amd_module('Youtube');
$datasetup[] = '"techOrder": ["youtube"]';
$datasetup[] = '"sources": [{"type": "video/youtube", "src":"' . $urls[0] . '"}]';
$sources = ''; // Do not specify