I'm creating a video repository for Kaltura where all videos are uploaded and housed on a remote server. Nothing is downloaded onto the Moodle file system. All media on Kaltura is reference via a unique URL (similar to YouTube).
The purpose of the plug-in is to allow the user to browse and select videos that belong to their Kaltura account. None of the Kaltura videos are physically stored in Moodle, instead the Kaltura repository plug-in uses the external file repository type and uses a URL address that pertains to a specific media file (for example: http://www.kaltura.com/index.php/kwidget/wid/_1234/uiconf_id/456/entry_id/asdf123/v/flash#<video name>). Navigating to this link will display the video in a Kaltura branded flash player.
However, in Moodle 2.3 and 2.4 there is a problem when previewing a video selected from the Kaltura repository plug-in. When a video is selected, the preview iframe is blank (in the case of Moodle 2.4 it returns an error message).
I've been able to determine the cause of the problem in Moodle 2.3 and 2.4, when it previously was not a problem in Moodle 2.0 - 2.2.
In pre Moodle 2.3 the core code was written to specifically handle youtube links in order for it to display properly (details in
MDL-33390). Luckily I was able to add a workaround to have the Kaltura videos display properly. The workaround was to add a /v/flash#video_name to the end of the URL to instruct Moodle to create the proper embed markup.
With Moodle 2.3 (and 2.4) this system has changed with the introduction of using an iframe in the preview dialog and relying on lib/medialib.php to determine the file extension (or URL) and using a player that suits the cirteria (similar to how the filter plug-ins work). Youtube (which is a video repository much like Kaltura is) gets core treatment in this area in order for it to work properly.
The main problem is that the Kaltura video links do not match any criteria used by Moodle standard media players in addition to the fact that there is no way for a repository plug-in to determine how to preview the selected file. The former is not an issue becuase a filter plug-in can be created to handle the links. However the latter is the issue of most concern as core code handles it.
Examples in the code
The following code snippets (from Moodle 2.3) are meant to help illustrate the problem I'm having with the preview code.
In the Kaltura repository code, a video listing is generated. Kaltura has the ability for user to upload video, images and music files. The purpose of the $video->name . '.mpg' line is to force Moodle to display a video listing icon (when not viewing files in icon mode in the file picker). The source URL is created and all other array elements are generically created. Notice the source url http://www.kaltura.com/index.php/kwidget/wid/_787032/uiconf_id/6709411/entry_id/1_h2no1nvq/v/flash
When the user selects a file from the repository, the lib/editor/tinymce/tiny_mce/188.8.131.52/plugins/moodlemedia/js/media.js script changes the inner HTML of a div to an iframe where the source url is *http://localhost/ack/kaltura.git/lib/editor/tinymce/tiny_mce/184.108.40.206/plugins/moodlemedia/preview.php?path=http://www.kaltura.com/index.php/kwidget/wid/_787032/uiconf_id/6709411/entry_id/1_h2no1nvq/v/flash*.
In preview.php the core media renderer is passed the URL. Inside the core media renderer all of the media players are passed the URL to determine whether it is a file that can be played. Most of them check the extension of the file contained in the URL. The youtube media player class checks to see if www.youtube.com is found in the URL; then returns the embed markup needed to display a Youtube video
As you can see the core code doesn't allow for external media repositories (that use URL with no file extention information) to properly preview the coutent before it is inserted by the user.
Allow repository plug-ins to generate their own embed/preview markup that can be used by the preview popup. Have an abstract preview class that can be overridden by a repository sub class, where embed markup can be returned to preview.php and the output echoed back to the iframe inner HTML.
The preview.php script can determine exactly which repository plug-in the URL is from if it is passed the repository id; once the id is passed to preview.php it can use the repository static method public static function get_repository_by_id($repositoryid, $context, $options = array()) and then call the preview overridden method.
Why change the way it works
1. Media repositories that work along the same lines as Youtube will run into the same difficult where Moodle core renderer will not know what to do with the URL.
2. Greater flexibility to determine how to handle the previewing of a file (example: having a company branded player used to preview the media file, or better handling of a non standard media format)
3. When changes need to be made maintainers only need to update code for their plug-in and not core rendering code
Let's open a discussion
I'm interested in hearing your thoughs about this proposal. As it has an effect on Moodle 2.3 and Moodle 2.4 (I've already tested against master) which is currently in development and I would like to create a plug-in that is fully supported by Moodle's core code.