MDL-58065 media_videojs: Add RTMP support.

This commit is contained in:
Ruslan Kabalin 2018-01-05 14:23:00 +00:00
parent 39fab18e27
commit 2e59aee791
3 changed files with 43 additions and 6 deletions

View File

@ -85,6 +85,14 @@ class media_videojs_plugin extends core_media_player_native {
// Fix for VideoJS/Chrome bug https://github.com/videojs/video.js/issues/423 .
$mimetype = 'video/mp4';
}
// If this is RTMP stream, adjust mimetype to those VideoJS suggests to use (either flash or mp4).
if ($url->get_scheme() === 'rtmp') {
if ($mimetype === 'video/x-flv') {
$mimetype = 'rtmp/flv';
} else {
$mimetype = 'rtmp/mp4';
}
}
$source = html_writer::empty_tag('source', array('src' => $url, 'type' => $mimetype));
$sources[] = $source;
if ($isaudio === null) {
@ -93,7 +101,8 @@ class media_videojs_plugin extends core_media_player_native {
if ($responsive === null) {
$responsive = core_useragent::supports_html5($extension);
}
if (!core_useragent::supports_html5($extension) && get_config('media_videojs', 'useflash')) {
if (($url->get_scheme() === 'rtmp' || !core_useragent::supports_html5($extension))
&& get_config('media_videojs', 'useflash')) {
$flashtech = true;
}
}
@ -240,15 +249,28 @@ class media_videojs_plugin extends core_media_player_native {
}
}
if (!get_config('media_videojs', 'useflash')) {
return parent::list_supported_urls($urls, $options);
}
// If Flash fallback is enabled we can not check if/when browser supports flash.
$extensions = $this->get_supported_extensions();
$rtmpallowed = get_config('media_videojs', 'rtmp') && get_config('media_videojs', 'useflash');
foreach ($urls as $url) {
$ext = core_media_manager::instance()->get_extension($url);
if (in_array('.' . $ext, $extensions)) {
// If RTMP support is disabled, skip the URL that is using RTMP (which
// might have been picked to the list by its valid extension).
if (!$rtmpallowed && ($url->get_scheme() === 'rtmp')) {
continue;
}
// If RTMP support is allowed, URL with RTMP scheme is supported irrespective to extension.
if ($rtmpallowed && ($url->get_scheme() === 'rtmp')) {
$result[] = $url;
continue;
}
if (!get_config('media_videojs', 'useflash')) {
return parent::list_supported_urls($urls, $options);
} else {
$ext = core_media_manager::instance()->get_extension($url);
if (in_array('.' . $ext, $extensions)) {
$result[] = $url;
}
}
}
return $result;
@ -310,14 +332,23 @@ class media_videojs_plugin extends core_media_player_native {
if (get_config('media_videojs', 'youtube')) {
$supports .= ($supports ? '<br>' : '') . get_string('youtube', 'media_videojs');
}
if (get_config('media_videojs', 'rtmp') && get_config('media_videojs', 'useflash')) {
$supports .= ($supports ? '<br>' : '') . get_string('rtmp', 'media_videojs');
}
return $supports;
}
public function get_embeddable_markers() {
$markers = parent::get_embeddable_markers();
// Add YouTube support if enabled.
if (get_config('media_videojs', 'youtube')) {
$markers = array_merge($markers, array('youtube.com', 'youtube-nocookie.com', 'youtu.be', 'y2u.be'));
}
// Add RTMP support if enabled.
if (get_config('media_videojs', 'rtmp') && get_config('media_videojs', 'useflash')) {
$markers[] = 'rtmp://';
}
return $markers;
}

View File

@ -29,6 +29,7 @@ $string['audioextensions'] = 'Audio file extensions';
$string['configaudiocssclass'] = 'A CSS class that will be added to the &lt;audio&gt; element.';
$string['configaudioextensions'] = 'A comma-separated list of supported audio file extensions. VideoJS will try to use the browser\'s native video player when available, and fall back to a Flash player for other formats if Flash is supported by the browser and Flash fallback is enabled below.';
$string['configlimitsize'] = 'If enabled, and width and height are not specified, the video will display with default width and height. Otherwise it will stretch to the maximum possible width.';
$string['configrtmp'] = 'If enabled, links that start with rtmp:// will be handled by the plugin, irrespective of whether its extension is enabled in the supported extensions setting. Notice that you need to enable flash fallback for this to work.';
$string['configvideocssclass'] = 'A CSS class that will be added to the &lt;video&gt; element. For example, the CSS class "vjs-big-play-centered" will place the play button in the middle. For details, including how to set a custom skin, see docs.videojs.com.';
$string['configvideoextensions'] = 'A comma-separated list of supported video file extensions. VideoJS will try to use the browser\'s native video player when available, and fall back to a Flash player for other formats if Flash is supported by the browser and Flash fallback is enabled below.';
$string['configyoutube'] = 'Use VideoJS to play YouTube videos. Note that YouTube playlists are not yet supported by VideoJS.';
@ -36,6 +37,7 @@ $string['configuseflash'] = 'Use Flash player if video format is not natively su
$string['limitsize'] = 'Limit size';
$string['pluginname'] = 'VideoJS player';
$string['pluginname_help'] = 'A JavaScript wrapper for video files played by the browser\'s native video player with a Flash player fallback. (Format support depends on the browser.)';
$string['rtmp'] = 'RTMP streams';
$string['videoextensions'] = 'Video file extensions';
$string['useflash'] = 'Use Flash fallback';
$string['videocssclass'] = 'CSS class for video';

View File

@ -36,6 +36,10 @@ if ($ADMIN->fulltree) {
new lang_string('configaudioextensions', 'media_videojs'),
'html_audio'));
$settings->add(new admin_setting_configcheckbox('media_videojs/rtmp',
new lang_string('rtmp', 'media_videojs'),
new lang_string('configrtmp', 'media_videojs'), 0));
$settings->add(new admin_setting_configcheckbox('media_videojs/useflash',
new lang_string('useflash', 'media_videojs'),
new lang_string('configuseflash', 'media_videojs'), 0));