-
Improvement
-
Resolution: Fixed
-
Minor
-
2.3
-
MOODLE_23_STABLE
-
MOODLE_23_STABLE
-
MDL-29624-master -
There are three areas in Moodle which have media embedding code:
1) Resource (used when you add a File or URL in 'Embed' mode, or in Lesson for the popup).
2) Filter (used when you put a link to <a href="somevideo.mp4"> in any text).
3) Moodle media preview (in TinyMCE when you select a media file to insert).
All three areas have different, totally independent code. This means the same code is duplicated three times (twice in PHP, once in JavaScript). In practice, the situation is actually worse than this because the code in resource is significantly worse than the code in filter, and different formats are supported using different approaches which work (or not) in different browsers.
In addition it is possible in a Moodle installation to customise #2 (by writing a new filter) but not possible to customise #1 and #3 at all without editing core code.
After discussion with other developers (including Petr I think) the best approach to resolve this problem was agreed. This work implements it as follows:
1) New core_media_renderer contains functions necessary to embed media. It is possible to override this renderer in a theme (achieving the customisation requirement).
2) The back-end to this class is in medialib.php and consists of a number of ranked 'player' classes (currently these are lightweight classes, not actual moodle plugins). It is easy to add extra classes either in core or inside a theme that extends the renderer as above.
The system works by outputting content using ALL player classes that support that content, in ranking order, via the object tag fallback mechanism.
Player classes were implemented starting from the existing functions in filter_mediaplugin.
There is significant unit testing for this feature.
3) filter_mediaplugin was changed to implement using these classes. (Obviously it is now very much smaller.) Language files and settings were moved from the filter into core_media. Existing unit test was updated to still pass.
4) I changed the resource (File) module to use this function as well, deleting all the resource code related to embedding media files. (Note: Resource still handles its own embedding of non-media files such as PDFs, HTML.)
5) I also changed the 'Moodle media' TinyMCE plugin so that instead of the custom JS embedding code, it adds an iframe to a new php script which outputs the media using the render_media function. [This removes the need to duplicate the code in JavaScript.]
6) I made necessary improvements to the HTML5 support, including:
a) Browser detection so that we can now have html5 support left on by default, without breaking fallbacks in the case where the browser does not support the video format in use.
b) Tweaks to work around bugs on Android versions which are still in wide use. This has now been tested to play on iDevices and Android when using any supported format.
I also wrote documentation for this proposed feature on the Moodle Docs wiki:
http://docs.moodle.org/dev/Media_embedding
- blocks
-
MDL-32707 media filter youtube videos should be transparent
- Closed
-
MDL-31368 Embedded HTML resources don't make full use of available space, and have extra scrollbars.
- Closed
- caused a regression
-
MDL-33114 import TinyMCE 3.5.1.1 and fix preview regressions
- Closed
- Discovered while testing
-
MDL-33116 new media embedding seems incompatible with slasharguments off
- Closed
- has a non-specific relationship to
-
MDL-32680 Import TinyMCE 3.5
- Closed
- has been marked as being related by
-
MDL-29987 Embedded PDF files cause problems in some configurations
- Closed
-
MDL-26648 Add google docs viewer as a display option in the file resource module
- Closed
- is duplicated by
-
MDL-30205 File Resource uses custom embed code
- Closed