MDL-66972 Files API: Add Streaming file mime type support

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.
This commit is contained in:
Matt Porritt 2019-10-21 15:20:34 +11:00 committed by Matt Porritt
parent 8cf4c97217
commit bdf62bba35
3 changed files with 29 additions and 3 deletions

View File

@ -96,7 +96,8 @@ abstract class core_filetypes {
'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'),
@ -275,6 +276,8 @@ abstract class core_filetypes {
'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')),

View File

@ -1122,7 +1122,7 @@ class core_useragent {
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.
@ -1171,7 +1171,7 @@ class core_useragent {
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;
}

View File

@ -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;
}