Skip to content

Commit

Permalink
MDL-66972 Files API: Add Streaming file mime type support
Browse files Browse the repository at this point in the history
Adds file type support for the streaming .fmp4, .ts, .m3u8, and .mpd media formats,
so that correct mime type is stored in the database and sent in
headers when files are served. Also update existing mime types for
stored files.
  • Loading branch information
Matt Porritt authored and Matt Porritt committed Dec 7, 2019
1 parent 8cf4c97 commit bdf62bb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/classes/filetypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ protected static function get_default_types() {
'flv' => array('type' => 'video/x-flv', 'icon' => 'flash',
'groups' => array('video', 'web_video'), 'string' => 'video'),
'f4v' => array('type' => 'video/mp4', 'icon' => 'flash', 'groups' => array('video', 'web_video'), 'string' => 'video'),

'fmp4' => array('type' => 'video/mp4', 'icon' => 'mpeg', 'groups' => array('html_video', 'video', 'web_video'),
'string' => 'video'),
'gallery' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'),
'galleryitem' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'),
'gallerycollection' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'),
Expand Down Expand Up @@ -275,6 +276,8 @@ protected static function get_default_types() {
'tex' => array('type' => 'application/x-tex', 'icon' => 'text'),
'texi' => array('type' => 'application/x-texinfo', 'icon' => 'text'),
'texinfo' => array('type' => 'application/x-texinfo', 'icon' => 'text'),
'ts' => array('type' => 'video/MP2T', 'icon' => 'mpeg', 'groups' => array('video', 'web_video'),
'string' => 'video'),
'tsv' => array('type' => 'text/tab-separated-values', 'icon' => 'text'),
'txt' => array('type' => 'text/plain', 'icon' => 'text', 'defaulticon' => true),
'vtt' => array('type' => 'text/vtt', 'icon' => 'text', 'groups' => array('html_track')),
Expand Down
4 changes: 2 additions & 2 deletions lib/classes/useragent.php
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ public static function is_moodle_app() {
public static function supports_html5($extension) {
$extension = strtolower($extension);

$supportedvideo = array('m4v', 'webm', 'ogv', 'mp4', 'mov');
$supportedvideo = array('m4v', 'webm', 'ogv', 'mp4', 'mov', 'fmp4');
$supportedaudio = array('ogg', 'oga', 'aac', 'm4a', 'mp3', 'wav', 'flac');

// Basic extension support.
Expand Down Expand Up @@ -1171,7 +1171,7 @@ public static function supports_html5($extension) {
return false;
}
// Mpeg is not supported in IE below 10.0.
$ismpeg = in_array($extension, ['m4a', 'mp3', 'm4v', 'mp4']);
$ismpeg = in_array($extension, ['m4a', 'mp3', 'm4v', 'mp4', 'fmp4']);
if ($ismpeg && (self::is_ie() && !self::check_ie_version('10.0'))) {
return false;
}
Expand Down
23 changes: 23 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3787,5 +3787,28 @@ function xmldb_main_upgrade($oldversion) {
// Automatically generated Moodle v3.8.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2019120500.00) {
// Upgrade MIME types for existing streaming files.
$filetypes = array(
'%.fmp4' => 'video/mp4',
'%.ts' => 'video/MP2T',
'%.mpd' => 'application/dash+xml',
'%.m3u8' => 'application/x-mpegURL',
);

$select = $DB->sql_like('filename', '?', false);
foreach ($filetypes as $extension => $mimetype) {
$DB->set_field_select(
'files',
'mimetype',
$mimetype,
$select,
array($extension)
);
}

upgrade_main_savepoint(true, 2019120500.00);
}

return true;
}

0 comments on commit bdf62bb

Please sign in to comment.