Skip to content

Commit

Permalink
MDL-58065 media_videojs: Add RTMP support.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin committed Apr 5, 2018
1 parent 39fab18 commit 2e59aee
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
43 changes: 37 additions & 6 deletions media/player/videojs/classes/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public function embed($urls, $name, $width, $height, $options) {
// 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) {
Expand All @@ -93,7 +101,8 @@ public function embed($urls, $name, $width, $height, $options) {
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;
}
}
Expand Down Expand Up @@ -240,15 +249,28 @@ public function list_supported_urls(array $urls, array $options = array()) {
}
}

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;
Expand Down Expand Up @@ -310,14 +332,23 @@ public function supports($usedextensions = []) {
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;
}

Expand Down
2 changes: 2 additions & 0 deletions media/player/videojs/lang/en/media_videojs.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
$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.';
$string['configuseflash'] = 'Use Flash player if video format is not natively supported by the browser. If enabled, VideoJS will be engaged for any file extension from the above list without browser check. Please note that Flash is not available in mobile browsers and discouraged in many desktop ones.';
$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';
Expand Down
4 changes: 4 additions & 0 deletions media/player/videojs/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
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));
Expand Down

0 comments on commit 2e59aee

Please sign in to comment.