diff --git a/lib/tests/medialib_test.php b/lib/tests/medialib_test.php index 6720de9f397..d2ccdc2a9dd 100644 --- a/lib/tests/medialib_test.php +++ b/lib/tests/medialib_test.php @@ -217,7 +217,7 @@ class core_medialib_testcase extends advanced_testcase { $this->assertContains($link, $t); // Enable media players that can play the same media formats. (ie. test & html5audio for mp3 files, etc.) - \core\plugininfo\media::set_enabled_plugins('html5video,html5audio,test,swf'); + \core\plugininfo\media::set_enabled_plugins('test,html5video,html5audio,swf'); $manager = core_media_manager::instance(); // Test media formats that can be played by 2 or more players. diff --git a/media/classes/manager.php b/media/classes/manager.php index 4982f2679be..40e7777a2ec 100644 --- a/media/classes/manager.php +++ b/media/classes/manager.php @@ -256,14 +256,15 @@ class core_media_manager { } } - if (empty($options[self::OPTION_FALLBACK_TO_BLANK]) || $out !== core_media_player::PLACEHOLDER) { - // Fallback to the link. Exception: in case of OPTION_FALLBACK_TO_BLANK and no other player matched do not fallback. - $text = $this->fallback_to_link($alternatives, $name, $options); - $out = str_replace(core_media_player::PLACEHOLDER, $text, $out); + if (!empty($options[self::OPTION_FALLBACK_TO_BLANK]) && $out === core_media_player::PLACEHOLDER) { + // In case of OPTION_FALLBACK_TO_BLANK and no player matched do not fallback to link, just return empty string. + return ''; } // Remove 'fallback' slot from final version and return it. - $out = str_replace(core_media_player::PLACEHOLDER, '', $out); + $fallback = $this->fallback_to_link($alternatives, $name, $options); + $out = str_replace(core_media_player::PLACEHOLDER, $fallback, $out); + $out = str_replace(core_media_player::LINKPLACEHOLDER, $fallback, $out); if (!empty($options[self::OPTION_BLOCK]) && $out !== '') { $out = html_writer::tag('div', $out, array('class' => 'resourcecontent')); } @@ -280,7 +281,7 @@ class core_media_manager { */ protected function fallback_to_link($urls, $name, $options) { // If link is turned off, return empty. - if (!empty($options[core_media_manager::OPTION_NO_LINK])) { + if (!empty($options[self::OPTION_NO_LINK])) { return ''; } @@ -290,7 +291,7 @@ class core_media_manager { if (strval($name) !== '' && $output === '') { $title = $name; } else { - $title = core_media_manager::instance()->get_filename($url); + $title = $this->get_filename($url); } $printlink = html_writer::link($url, $title, array('class' => 'mediafallbacklink')); if ($output) { diff --git a/media/classes/player.php b/media/classes/player.php index 9afdce0962f..f7d50ada966 100644 --- a/media/classes/player.php +++ b/media/classes/player.php @@ -53,6 +53,13 @@ abstract class core_media_player { */ const PLACEHOLDER = ''; + /** + * Placeholder text used to indicate where the link fallback is placed. + * No other players will apply to it but it will be converted to the link in the + * end (unless prevented by OPTION_NO_LINK). + */ + const LINKPLACEHOLDER = ''; + /** * Generates code required to embed the player. * diff --git a/media/player/html5audio/classes/plugin.php b/media/player/html5audio/classes/plugin.php index f501c81472a..2b375075169 100644 --- a/media/player/html5audio/classes/plugin.php +++ b/media/player/html5audio/classes/plugin.php @@ -65,7 +65,9 @@ class media_html5audio_plugin extends core_media_player_native { $size = 'width="' . $width . '"'; } - $fallback = core_media_player::PLACEHOLDER; + // We don't want fallback to another player because list_supported_urls() is already smart. + // Otherwise we could end up with nested