Merge branch 'MDL-58065-master' of https://github.com/lucisgit/moodle

This commit is contained in:
Andrew Nicols
2018-04-10 08:54:12 +08:00
4 changed files with 137 additions and 6 deletions
+37 -6
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;
}
@@ -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';
+4
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));
@@ -79,6 +79,19 @@ class media_videojs_testcase extends advanced_testcase {
$this->assertTrue(in_array('.mp3', $player->get_supported_extensions()));
$this->assertFalse(in_array('.ra', $player->get_supported_extensions()));
$this->assertEmpty(array_diff($player->get_supported_extensions(), $nativeextensions));
// Try to use flash extensions and make sure they are not returned as supported.
set_config('videoextensions', '.flv,.f4v', 'media_videojs');
$player = new media_videojs_plugin();
$this->assertFalse(in_array('.flv', $player->get_supported_extensions()));
$this->assertFalse(in_array('.f4v', $player->get_supported_extensions()));
// Enable flash and test if flash extenstions are supported.
set_config('useflash', 1, 'media_videojs');
set_config('videoextensions', '.flv,.f4v', 'media_videojs');
$player = new media_videojs_plugin();
$this->assertTrue(in_array('.flv', $player->get_supported_extensions()));
$this->assertTrue(in_array('.f4v', $player->get_supported_extensions()));
}
/**
@@ -228,6 +241,11 @@ class media_videojs_testcase extends advanced_testcase {
$this->assertNotRegExp('~somethinginvalid~i', $content);
}
/**
* Helper function for testing youtube videos embedding.
*
* @param string $t output of core_media_manager::embed_url.
*/
protected function youtube_plugin_engaged($t) {
$this->assertContains('mediaplugin_videojs', $t);
$this->assertContains('data-setup-lazy="{&quot;techOrder&quot;: [&quot;youtube&quot;]', $t);
@@ -281,4 +299,80 @@ class media_videojs_testcase extends advanced_testcase {
$this->assertNotContains('mediaplugin_videojs', $t);
}
/**
* Helper function for testing flash videos embedding.
*
* @param string $t output of core_media_manager::embed_url.
*/
protected function flash_plugin_engaged($t) {
$this->assertContains('mediaplugin_videojs', $t);
$this->assertContains('data-setup-lazy="{&quot;techOrder&quot;: [&quot;flash&quot;, &quot;html5&quot;]', $t);
}
/**
* Test that VideoJS can embed flash videos.
*/
public function test_flash() {
$manager = core_media_manager::instance();
// Flash enabled.
set_config('useflash', 1, 'media_videojs');
$url = new moodle_url('http://example.org/some_filename.flv');
$t = $manager->embed_url($url);
$this->flash_plugin_engaged($t);
$this->assertRegExp('~</video>~', $t);
$this->assertRegExp('~<source src="http://example.org/some_filename.flv"~', $t);
$this->assertRegExp('~<a class="mediafallbacklink" href="http://example.org/some_filename.flv">some_filename.flv</a>~', $t);
// Flash disabled.
set_config('useflash', 0, 'media_videojs');
$url = new moodle_url('http://example.org/some_filename.flv');
$t = $manager->embed_url($url);
$this->assertNotContains('mediaplugin_videojs', $t);
$this->assertRegExp('~<a class="mediafallbacklink" href="http://example.org/some_filename.flv">some_filename.flv</a>~', $t);
}
/**
* Test that VideoJS can embed RTMP streams.
*/
public function test_rtmp() {
$manager = core_media_manager::instance();
// RTMP disabled, flash disabled.
set_config('useflash', 0, 'media_videojs');
set_config('rtmp', 0, 'media_videojs');
$url = new moodle_url('rtmp://example.com/fms&mp4:path/to/file.mp4');
$t = $manager->embed_url($url);
$this->assertNotContains('mediaplugin_videojs', $t);
$this->assertRegExp('~<a class="mediafallbacklink" href="rtmp://example.com/fms&mp4:path/to/file.mp4">file.mp4</a>~', $t);
// RTMP enabled, flash disabled.
set_config('useflash', 0, 'media_videojs');
set_config('rtmp', 1, 'media_videojs');
$url = new moodle_url('rtmp://example.com/fms&mp4:path/to/file.mp4');
$t = $manager->embed_url($url);
$this->assertNotContains('mediaplugin_videojs', $t);
$this->assertRegExp('~<a class="mediafallbacklink" href="rtmp://example.com/fms&mp4:path/to/file.mp4">file.mp4</a>~', $t);
// RTMP enabled, flash enabled, rtmp/mp4 type expected.
set_config('useflash', 1, 'media_videojs');
set_config('rtmp', 1, 'media_videojs');
$url = new moodle_url('rtmp://example.com/fms&mp4:path/to/file.mp4');
$t = $manager->embed_url($url);
$this->flash_plugin_engaged($t);
$this->assertRegExp('~</video>~', $t);
$this->assertRegExp('~<source src="rtmp://example.com/fms&mp4:path/to/file.mp4" type="rtmp/mp4"~', $t);
$this->assertRegExp('~<a class="mediafallbacklink" href="rtmp://example.com/fms&mp4:path/to/file.mp4">file.mp4</a>~', $t);
// RTMP enabled, flash enabled, rtmp/flv type expected.
set_config('useflash', 1, 'media_videojs');
set_config('rtmp', 1, 'media_videojs');
$url = new moodle_url('rtmp://example.com/fms&flv:path/to/file.flv');
$t = $manager->embed_url($url);
$this->flash_plugin_engaged($t);
$this->assertRegExp('~</video>~', $t);
$this->assertRegExp('~<source src="rtmp://example.com/fms&flv:path/to/file.flv" type="rtmp/flv"~', $t);
$this->assertRegExp('~<a class="mediafallbacklink" href="rtmp://example.com/fms&flv:path/to/file.flv">file.flv</a>~', $t);
}
}