mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-63453 media_videojs: Use media_source mimetype group in the player.
This commit is contained in:
parent
037124bf1c
commit
a742b03d8c
4 changed files with 25 additions and 47 deletions
|
@ -1167,14 +1167,13 @@ class core_useragent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if current browser supports the HLS and MPEG-DASH video
|
* Checks if current browser supports the HLS and MPEG-DASH media
|
||||||
* streaming formats. Most browsers get this from Media Source Extensions.
|
* streaming formats. Most browsers get this from Media Source Extensions.
|
||||||
* Safari on iOS, doesn't support MPEG-DASH at all.
|
* Safari on iOS, doesn't support MPEG-DASH at all.
|
||||||
*
|
*
|
||||||
* Note, the check here is not 100% accurate!
|
* Note, the check here is not 100% accurate!
|
||||||
*
|
*
|
||||||
* Also we assume that users of Firefox/Chrome/Safari do not use the ancient versions of browsers.
|
* Also we assume that users of Firefox/Chrome/Safari do not use the ancient versions of browsers.
|
||||||
*
|
|
||||||
* We check the exact version for IE/Edge though. We know that there are still users of very old
|
* We check the exact version for IE/Edge though. We know that there are still users of very old
|
||||||
* versions that are afraid to upgrade or have slow IT department.
|
* versions that are afraid to upgrade or have slow IT department.
|
||||||
*
|
*
|
||||||
|
@ -1183,6 +1182,7 @@ class core_useragent {
|
||||||
* https://caniuse.com/#search=mpeg-dash
|
* https://caniuse.com/#search=mpeg-dash
|
||||||
* https://caniuse.com/#search=hls
|
* https://caniuse.com/#search=hls
|
||||||
*
|
*
|
||||||
|
* @param string $extension
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function supports_media_source_extensions(string $extension) : bool {
|
public static function supports_media_source_extensions(string $extension) : bool {
|
||||||
|
@ -1192,7 +1192,7 @@ class core_useragent {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($extension == '.mpd') {
|
if ($extension == '.mpd') {
|
||||||
// Not supported is iOS on Safari.
|
// Not supported in Safari on iOS.
|
||||||
if (self::is_safari_ios()) {
|
if (self::is_safari_ios()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,32 +226,14 @@ class media_videojs_plugin extends core_media_player_native {
|
||||||
$filetypes = preg_split('/\s*,\s*/',
|
$filetypes = preg_split('/\s*,\s*/',
|
||||||
strtolower(trim(get_config('media_videojs', 'videoextensions') . ',' .
|
strtolower(trim(get_config('media_videojs', 'videoextensions') . ',' .
|
||||||
get_config('media_videojs', 'audioextensions'))));
|
get_config('media_videojs', 'audioextensions'))));
|
||||||
$configuredextensions = file_get_typegroup('extension', $filetypes);
|
|
||||||
|
|
||||||
// If Flash is disabled get extensions natively supported by browsers,
|
$this->extensions = file_get_typegroup('extension', $filetypes);
|
||||||
if (!get_config('media_videojs', 'useflash')) {
|
if ($this->extensions && !get_config('media_videojs', 'useflash')) {
|
||||||
$nativeextensions = array_merge(file_get_typegroup('extension', 'html_video'),
|
// If Flash is disabled get extensions supported by player that don't rely on flash.
|
||||||
file_get_typegroup('extension', 'html_audio'));
|
$supportedextensions = array_merge(file_get_typegroup('extension', 'html_video'),
|
||||||
} else {
|
file_get_typegroup('extension', 'html_audio'), file_get_typegroup('extension', 'media_source'));
|
||||||
// If we have Flash fallback enabled pass through all configured extensions.
|
$this->extensions = array_intersect($this->extensions, $supportedextensions);
|
||||||
$nativeextensions = $configuredextensions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle HLS and MPEG-DASH if in configured extensions.
|
|
||||||
// This is a bit of a hassle because of browser compatibility differences.
|
|
||||||
$msextensions = array();
|
|
||||||
if (in_array('.m3u8', $configuredextensions) && core_useragent::supports_media_source_extensions('.m3u8')) {
|
|
||||||
$msextensions[] = '.m3u8';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_array('.mpd', $configuredextensions) && core_useragent::supports_media_source_extensions('.mpd')) {
|
|
||||||
$msextensions[] = '.mpd';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Final supported extensions are intersection of user configured extensions
|
|
||||||
// and extensions the browser and videoJS support based on player configuration.
|
|
||||||
$supportedextensions = array_merge($nativeextensions, $msextensions);
|
|
||||||
$this->extensions = array_intersect($configuredextensions, $supportedextensions);
|
|
||||||
}
|
}
|
||||||
return $this->extensions;
|
return $this->extensions;
|
||||||
}
|
}
|
||||||
|
@ -270,7 +252,6 @@ class media_videojs_plugin extends core_media_player_native {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If Flash fallback is enabled we can not check if/when browser supports flash.
|
|
||||||
$extensions = $this->get_supported_extensions();
|
$extensions = $this->get_supported_extensions();
|
||||||
$rtmpallowed = get_config('media_videojs', 'rtmp') && get_config('media_videojs', 'useflash');
|
$rtmpallowed = get_config('media_videojs', 'rtmp') && get_config('media_videojs', 'useflash');
|
||||||
foreach ($urls as $url) {
|
foreach ($urls as $url) {
|
||||||
|
@ -279,6 +260,7 @@ class media_videojs_plugin extends core_media_player_native {
|
||||||
if (!$rtmpallowed && ($url->get_scheme() === 'rtmp')) {
|
if (!$rtmpallowed && ($url->get_scheme() === 'rtmp')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If RTMP support is allowed, URL with RTMP scheme is supported irrespective to extension.
|
// If RTMP support is allowed, URL with RTMP scheme is supported irrespective to extension.
|
||||||
if ($rtmpallowed && ($url->get_scheme() === 'rtmp')) {
|
if ($rtmpallowed && ($url->get_scheme() === 'rtmp')) {
|
||||||
$result[] = $url;
|
$result[] = $url;
|
||||||
|
@ -286,26 +268,23 @@ class media_videojs_plugin extends core_media_player_native {
|
||||||
}
|
}
|
||||||
|
|
||||||
$ext = '.' . core_media_manager::instance()->get_extension($url);
|
$ext = '.' . core_media_manager::instance()->get_extension($url);
|
||||||
|
// Handle HLS and MPEG-DASH if supported.
|
||||||
|
$isstream = in_array($ext, file_get_typegroup('extension', 'media_source'));
|
||||||
|
if ($isstream && in_array($ext, $extensions) && core_useragent::supports_media_source_extensions($ext)) {
|
||||||
|
$result[] = $url;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!get_config('media_videojs', 'useflash')) {
|
if (!get_config('media_videojs', 'useflash')) {
|
||||||
$result = parent::list_supported_urls($urls, $options);
|
return parent::list_supported_urls($urls, $options);
|
||||||
} else {
|
} else {
|
||||||
|
// If Flash fallback is enabled we can not check if/when browser supports flash.
|
||||||
|
// We assume it will be able to handle any other extensions that player supports.
|
||||||
if (in_array($ext, $extensions)) {
|
if (in_array($ext, $extensions)) {
|
||||||
$result[] = $url;
|
$result[] = $url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle HLS and MPEG-DASH if in configured extensions.
|
|
||||||
// This is a bit of a hassle because of browser compatibility differences.
|
|
||||||
if ($ext == '.m3u8' && core_useragent::supports_media_source_extensions('.m3u8')) {
|
|
||||||
$result[] = $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($ext == '.mpd' && core_useragent::supports_media_source_extensions('.mpd')) {
|
|
||||||
$result[] = $url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ if ($ADMIN->fulltree) {
|
||||||
$settings->add(new admin_setting_filetypes('media_videojs/videoextensions',
|
$settings->add(new admin_setting_filetypes('media_videojs/videoextensions',
|
||||||
new lang_string('videoextensions', 'media_videojs'),
|
new lang_string('videoextensions', 'media_videojs'),
|
||||||
new lang_string('configvideoextensions', 'media_videojs'),
|
new lang_string('configvideoextensions', 'media_videojs'),
|
||||||
'html_video,.f4v,.flv,.m3u8,.mpd',
|
'html_video,media_source,.f4v,.flv',
|
||||||
array('onlytypes' => array('video', 'web_video', 'html_video', 'html_track'))));
|
array('onlytypes' => array('video', 'web_video', 'html_video', 'media_source'))));
|
||||||
|
|
||||||
$settings->add(new admin_setting_filetypes('media_videojs/audioextensions',
|
$settings->add(new admin_setting_filetypes('media_videojs/audioextensions',
|
||||||
new lang_string('audioextensions', 'media_videojs'),
|
new lang_string('audioextensions', 'media_videojs'),
|
||||||
|
|
|
@ -61,16 +61,15 @@ class media_videojs_testcase extends advanced_testcase {
|
||||||
* Test method get_supported_extensions()
|
* Test method get_supported_extensions()
|
||||||
*/
|
*/
|
||||||
public function test_supported_extensions() {
|
public function test_supported_extensions() {
|
||||||
$msextensions = array('.m3u8', '.mpd');
|
$supportedextensions = array_merge(file_get_typegroup('extension', 'html_video'),
|
||||||
$nativeextensions = array_merge(file_get_typegroup('extension', 'html_video'),
|
file_get_typegroup('extension', 'html_audio'), file_get_typegroup('extension', 'media_source'));
|
||||||
file_get_typegroup('extension', 'html_audio'), $msextensions);
|
|
||||||
|
|
||||||
set_config('useflash', 0, 'media_videojs');
|
set_config('useflash', 0, 'media_videojs');
|
||||||
|
|
||||||
// Make sure that the list of extensions from the setting is filtered to HTML5 natively supported extensions.
|
// Make sure that the list of extensions from the setting is filtered to HTML5 natively supported extensions.
|
||||||
$player = new media_videojs_plugin();
|
$player = new media_videojs_plugin();
|
||||||
$this->assertTrue(in_array('.mp3', $player->get_supported_extensions()));
|
$this->assertTrue(in_array('.mp3', $player->get_supported_extensions()));
|
||||||
$this->assertEmpty(array_diff($player->get_supported_extensions(), $nativeextensions));
|
$this->assertEmpty(array_diff($player->get_supported_extensions(), $supportedextensions));
|
||||||
|
|
||||||
// Try to set the audioextensions to something non-native (.ra) and make sure it is not returned as supported.
|
// Try to set the audioextensions to something non-native (.ra) and make sure it is not returned as supported.
|
||||||
set_config('audioextensions', '.mp3,.wav,.ra', 'media_videojs');
|
set_config('audioextensions', '.mp3,.wav,.ra', 'media_videojs');
|
||||||
|
@ -78,7 +77,7 @@ class media_videojs_testcase extends advanced_testcase {
|
||||||
$this->assertNotEmpty($player->get_supported_extensions());
|
$this->assertNotEmpty($player->get_supported_extensions());
|
||||||
$this->assertTrue(in_array('.mp3', $player->get_supported_extensions()));
|
$this->assertTrue(in_array('.mp3', $player->get_supported_extensions()));
|
||||||
$this->assertFalse(in_array('.ra', $player->get_supported_extensions()));
|
$this->assertFalse(in_array('.ra', $player->get_supported_extensions()));
|
||||||
$this->assertEmpty(array_diff($player->get_supported_extensions(), $nativeextensions));
|
$this->assertEmpty(array_diff($player->get_supported_extensions(), $supportedextensions));
|
||||||
|
|
||||||
// Try to use flash extensions and make sure they are not returned as supported.
|
// Try to use flash extensions and make sure they are not returned as supported.
|
||||||
set_config('videoextensions', '.flv,.f4v', 'media_videojs');
|
set_config('videoextensions', '.flv,.f4v', 'media_videojs');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue