From efbf41e84691c072fdc1626bfc5c1160bf976419 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 15 Mar 2019 10:34:14 +0100 Subject: [PATCH] Show mp3 files correctly when added in a LP see BT#15416 --- main/document/showinframes.php | 12 +++++------- main/inc/lib/display.lib.php | 22 ++++++++++++++++++++-- main/inc/lib/document.lib.php | 26 ++++++++++++++------------ main/lp/learnpath.class.php | 4 ++-- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/main/document/showinframes.php b/main/document/showinframes.php index 3b157fe27a..d7de46bdf2 100755 --- a/main/document/showinframes.php +++ b/main/document/showinframes.php @@ -103,7 +103,7 @@ if (!$is_allowed_to_edit && !$is_visible) { } $pathinfo = pathinfo($header_file); -$playerSupportedFiles = ['mp4', 'ogv', 'flv', 'm4v', 'webm']; +$playerSupportedFiles = ['mp3', 'mp4', 'ogv', 'flv', 'm4v', 'webm']; $playerSupported = false; if (in_array(strtolower($pathinfo['extension']), $playerSupportedFiles)) { $playerSupported = true; @@ -188,7 +188,7 @@ if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) { var topbarHeight = $("#topbar").height(); $("#viewerJSContent").height((bodyHeight - topbarHeight)); } - $(document).ready(function() { + $(function() { $(window).resize(resizeIframe()); }); ' @@ -261,12 +261,11 @@ if ($originIsLearnpath) { Display::display_header(''); } -echo '
'; - $file_url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$header_file; $file_url_web = $file_url.'?'.api_get_cidreq(); if ($show_web_odf) { + echo '
'; $browser = api_get_navigator(); $pdfUrl = api_get_path(WEB_LIBRARY_PATH).'javascript/ViewerJS/index.html#'.$file_url; if ($browser['name'] == 'Mozilla' && preg_match('|.*\.pdf|i', $header_file)) { @@ -277,12 +276,11 @@ if ($show_web_odf) { src="'.$pdfUrl.'"> '; echo '
'; + echo '
'; } -echo ''; - if ($playerSupported) { - echo DocumentManager::generateVideoPreview($file_url_web, $extension); + echo DocumentManager::generateMediaPreview($file_url_web, $extension); } if ($is_freemind_available) { diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 06973f7061..2c7ecd08d5 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -2806,12 +2806,16 @@ HTML; { $defaultFeatures = ['playpause', 'current', 'progress', 'duration', 'tracks', 'volume', 'fullscreen', 'vrview']; $features = api_get_configuration_value('video_features'); + $bowerJsFiles = []; + $bowerCSSFiles = []; if (!empty($features) && isset($features['features'])) { foreach ($features['features'] as $feature) { if ($feature === 'vrview') { continue; } $defaultFeatures[] = $feature; + $bowerJsFiles[] = "mediaelement/plugins/$feature/$feature.js"; + $bowerCSSFiles[] = "mediaelement/plugins/$feature/$feature.css"; } } @@ -2821,11 +2825,24 @@ HTML; $translateHtml = '{type:"script", id:"_fr4", src:"'.api_get_path(WEB_AJAX_PATH).'lang.ajax.php?a=translate_html&'.api_get_cidreq().'"},'; } + $counter = 10; + $extraMediaFiles = ''; + foreach ($bowerJsFiles as $file) { + $extraMediaFiles .= '{type: "script", id: "media_'.$counter.'", src: "'.api_get_path(WEB_PUBLIC_PATH).'assets/'.$file.'"},'; + $counter++; + } + + foreach ($bowerCSSFiles as $file) { + $extraMediaFiles .= '{type: "stylesheet", id: "media_'.$counter.'", src: "'.api_get_path(WEB_PUBLIC_PATH).'assets/'.$file.'"},'; + $counter++; + } + + $defaultFeatures = implode("','", $defaultFeatures); $frameReady = ' $.frameReady(function() { - $(document).ready(function () { - $("video:not(.skip), audio:not(.skip)").mediaelementplayer({ + $(function() { + $("video:not(.skip), audio:not(.skip)").mediaelementplayer({ pluginPath: "'.api_get_path(WEB_PUBLIC_PATH).'assets/mediaelement/build/", features: ["'.$defaultFeatures.'"], success: function(mediaElement, originalNode, instance) { @@ -2847,6 +2864,7 @@ HTML; {type: "stylesheet", id: "_media2", src: "'.api_get_path(WEB_PUBLIC_PATH).'assets/mediaelement/build/mediaelementplayer.min.css"}, {type: "stylesheet", id: "_media4", src: "'.api_get_path(WEB_PUBLIC_PATH).'assets/mediaelement/plugins/vrview/vrview.css"}, {type: "script", id: "_media4", src: "'.api_get_path(WEB_PUBLIC_PATH).'assets/mediaelement/plugins/vrview/vrview.js"}, + '.$extraMediaFiles.' '.$translateHtml.' ] });'; diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 93e961ea97..bff492f8de 100644 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -3212,19 +3212,21 @@ class DocumentManager * * @return string */ - public static function generateVideoPreview($file, $extension) + public static function generateMediaPreview($file, $extension) { - $type = ''; - /*if ($extension != 'flv') { - - }*/ - //$type = "video/$extension"; - //$fileInfo = parse_url($file); - //$type = self::file_get_mime_type(basename($fileInfo['path'])); - - $html = ''; + $id = api_get_unique_id(); + switch ($extension) { + case 'mp3': + $document_data['file_extension'] = $extension; + $html = '
'; + $html .= '
'; + break; + default: + $html = ''; + break; + } return $html; } diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 8f402d32a3..f7c20bda56 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -13491,9 +13491,9 @@ EOD; } $documentPathInfo = pathinfo($document->getPath()); - $jplayerSupportedFiles = ['mp4', 'ogv', 'flv', 'm4v']; + $mediaSupportedFiles = ['mp3', 'mp4', 'ogv', 'flv', 'm4v']; $extension = isset($documentPathInfo['extension']) ? $documentPathInfo['extension'] : ''; - $showDirectUrl = !in_array($extension, $jplayerSupportedFiles); + $showDirectUrl = !in_array($extension, $mediaSupportedFiles); $openmethod = 2; $officedoc = false;