function fetchSimpleAudioPlayer($runtime, $rtmp_file, $protocol = "", $width = "450", $height = "25", $embed = false, $embedstring = "Play", $permitfullscreen = false, $usepoodlldata = false, $splashurl = '') { global $CFG, $USER, $COURSE; //Set our servername . $flvserver = $CFG->poodll_media_server; $courseid = $COURSE->id; $useplayer = $CFG->filter_poodll_defaultplayer; //determine if we are on a mobile device or not $ismobile = isMobile($CFG->filter_poodll_html5play); //Set our use protocol type //if one was not passed, then it may have been tagged to the url //this was the old way. if ($protocol == "") { $type = "rtmp"; if (strlen($rtmp_file) > 5) { $protocol = substr($rtmp_file, 0, 5); switch ($protocol) { case "yutu:": $rtmp_file = substr($rtmp_file, 5); $rtmp_file = getYoutubeLink($rtmp_file); $type = "http"; break; case "http:": $rtmp_file = substr($rtmp_file, 5); $type = "http"; break; case "rtmp:": $rtmp_file = substr($rtmp_file, 5); default: $type = "rtmp"; } } //end of if strlen(rtmpfile) > 4 //If we have one passed in, lets set it to our type } else { switch ($protocol) { case "yutu": $rtmp_file = getYoutubeLink($rtmp_file); $type = "http"; break; case "http": case "rtmp": case "legacy": default: $type = $protocol; } } //some common variables for the embedding stage. //$playerLoc = $CFG->wwwroot . '/filter/poodll/flash/poodllaudioplayer.lzx.swf9.swf'; //If we are using the legacy coursefiles, we want to fall into this code //this is just a temporary fix to achieve this. Justin 20111213 if ($protocol == 'rtmp' || $protocol == 'legacy') { $rtmp_file = $CFG->wwwroot . "/file.php/" . $courseid . "/" . $rtmp_file; $type = 'http'; //if using poodlldata, take stub from base dir + poodlldatadir then add file name/path } else { if ($usepoodlldata) { $baseURL = $CFG->{'wwwroot'} . "/" . $CFG->{'filter_poodll_datadir'} . "/"; $rtmp_file = $baseURL . $rtmp_file; } } //If we want to avoid loading many players per page, this loads the player only after a text link is clicked //it uses the poodll player and only works if the file is an flv, otherwise it just proceeds as usual //I quit loading javascript.php in head, so loadAudioPlayer won't work. I think noone uses it anyway. hence added if "false" //Justin 20130406 if (false && $embed && substr($rtmp_file, -4) == '.flv') { $lzid = "lzapp_audioplayer_" . rand(100000, 999999); $returnString = "\t\t\n\t\t <div id='{$lzid}' class='player'>\n <a href='#' onclick=\"javascript:loadAudioPlayer('{$rtmp_file}', '{$lzid}', 'sample_{$lzid}', '{$width}', '{$height}'); return false;\">{$embedstring} </a>\n </div>\t\t\n\t\t"; return $returnString; } //if we are using javascript to detect and insert (probably best..?) $params = array(); $params['red5url'] = urlencode($flvserver); $params['playertype'] = $type; $params['mediapath'] = $rtmp_file; $params['permitfullscreen'] = $permitfullscreen; //establish the fileextension $ext = substr($rtmp_file, -3); //if we are on mobile we want to play mp3 using html5 tags //if we have a file type that flash wont play, default to runtime = js if ($runtime == 'auto') { if ($ismobile) { $runtime = 'js'; } else { if ($ext == '3gp' || $ext == 'ebm' || $ext == '3g2') { $runtime = 'js'; } else { $runtime = 'swf'; } } } //end of if runtime=auto if ($runtime == 'js' && $CFG->filter_poodll_html5controls == 'native') { $returnString = ""; //the $rtmp_file as it comes from assignment and questions, is urlencoded, we need to decode //or html 5 playback will fail Justin 20121016 $rtmp_file = urldecode($rtmp_file); //figure out the mime type by the extension $mime = ""; switch ($ext) { case "mov": case "mp4": $mime = "video/mp4"; break; case "3gp": $mime = "video/3gpp"; break; case "3g2": $mime = "video/3gpp2"; break; case "ebm": $mime = "video/webm"; break; default: $mime = "video/mp4"; } //The HTML5 Code (can be used on its own OR with the mediaelement code below it $returnString .= "<audio controls width='" . $width . "' height='" . $height . "'>\n\t\t\t\t\t\t\t\t<source type='" . $mime . "' src='" . $rtmp_file . "'/>\n\t\t\t\t\t\t\t\t</audio>"; //======================= //if we are using mediaelement js use this. We use JQuery which is not ideal, in moodle yui environment /* $mediajsroot = $CFG->wwwroot . '/filter/poodll/js/mediaelementjs/'; $returnString .="<script src='" . $mediajsroot . "jquery.js'></script>"; $returnString .="<script src='" . $mediajsroot . "mediaelement-and-player.min.js'></script>"; $returnString .="<link rel='stylesheet' href='" . $mediajsroot . "mediaelementplayer.css' /> "; $returnString .="<script src='" . $mediajsroot . "mep-feature-loop.js'></script>"; $returnString .="<script src='" . $mediajsroot . "mep-feature-speed.js'></script>"; $returnString .="<script src='" . $mediajsroot . "mep-feature-progress.js'></script>"; //$returnString .="<script>$('audio,video').mediaelementplayer({features:['playpause','loop','speed','progess','volume']});</script>"; $returnString .="<script>$('audio,video').mediaelementplayer();</script>"; */ //======================= //======================= //If we use Kaltura, use this //$returnString .="<script src='http://html5.kaltura.org/js'></script>"; //======================= //if we are using SWF } else { //Flowplayer if ($useplayer == "fp" || $CFG->filter_poodll_html5controls == "js") { $returnString = fetchFlowPlayerCode($width, $height, $rtmp_file, "audio", $ismobile, "", false, $splashurl); //JW player } else { if ($useplayer == "jw") { $flashvars = array(); $flashvars['file'] = $rtmp_file; $flashvars['autostart'] = 'false'; $returnString = fetchSWFObjectWidgetCode('jwplayer.swf', $flashvars, $width, $height, '#FFFFFF'); //if the file is an mp3, and we are using poodll player, don't handle it //either pass it to multi media plugin filter or pass it flowplayer // PoodLL player can't mp3 without RTMP } else { if (substr($rtmp_file, -4) == '.mp3') { $returnString = fetchFlowPlayerCode($width, $height, $rtmp_file, "audio", $ismobile); //$returnString= "<a href=\"$rtmp_file\">$rtmp_file</a>"; //PoodLL Player } else { $returnString = fetchSWFWidgetCode('poodllaudioplayer.lzx.swf9.swf', $params, $width, $height, '#FFFFFF'); } } } //regardless of swf player, add a download icon if appropriate $context = context_course::instance($COURSE->id); $has_permission = has_capability('filter/poodll:candownloadmedia', $context); if ($CFG->filter_poodll_download_media_ok && $has_permission) { $returnString .= "<a href='" . urldecode($rtmp_file) . "'>" . " <img src='" . $CFG->{'wwwroot'} . "/filter/poodll/pix/download.gif' alt='download' />" . "</a>"; } } return $returnString; }
public static function fetchSimpleAudioPlayer($runtime, $rtmp_file, $protocol = "", $width = "450", $height = "25", $embed = false, $embedstring = "Play", $permitfullscreen = false, $usepoodlldata = false, $splashurl = '') { global $CFG, $COURSE, $PAGE; //Set our servername . $flvserver = self::fetch_mediaserver_url(); $courseid = $COURSE->id; $useplayer = $CFG->filter_poodll_defaultplayer; //determine if we are on a mobile device or not $ismobile = self::isMobile($CFG->filter_poodll_html5play); //Set our use protocol type //if one was not passed, then it may have been tagged to the url //this was the old way. if ($protocol == "") { $type = "rtmp"; if (strlen($rtmp_file) > 5) { $protocol = substr($rtmp_file, 0, 5); switch ($protocol) { case "yutu:": $rtmp_file = substr($rtmp_file, 5); $rtmp_file = getYoutubeLink($rtmp_file); $type = "http"; break; case "http:": $rtmp_file = substr($rtmp_file, 5); $type = "http"; break; case "rtmp:": $rtmp_file = substr($rtmp_file, 5); default: $type = "rtmp"; } } //end of if strlen(rtmpfile) > 4 //If we have one passed in, lets set it to our type } else { switch ($protocol) { case "yutu": $rtmp_file = getYoutubeLink($rtmp_file); $type = "http"; break; case "http": case "rtmp": case "legacy": default: $type = $protocol; } } //If we are using the legacy coursefiles, we want to fall into this code //this is just a temporary fix to achieve this. Justin 20111213 if ($protocol == 'rtmp' || $protocol == 'legacy') { $rtmp_file = $CFG->wwwroot . "/file.php/" . $courseid . "/" . $rtmp_file; $type = 'http'; //if using poodlldata, take stub from base dir + poodlldatadir then add file name/path } else { if ($usepoodlldata) { $baseURL = $CFG->{'wwwroot'} . "/" . $CFG->{'filter_poodll_datadir'} . "/"; $rtmp_file = $baseURL . $rtmp_file; } } //if we are using javascript to detect and insert (probably best..?) $params = array(); $params['red5url'] = urlencode($flvserver); $params['playertype'] = $type; $params['mediapath'] = $rtmp_file; $params['permitfullscreen'] = $permitfullscreen; //establish the fileextension $ext = substr($rtmp_file, -3); //if we are on mobile we want to play mp3 using html5 tags //if we have a file type that flash wont play, default to runtime = js if ($runtime == 'auto') { if ($ismobile) { $runtime = 'js'; } else { if ($ext == '3gp' || $ext == 'ebm' || $ext == '3g2') { $runtime = 'js'; } else { $runtime = 'swf'; } } } //end of if runtime=auto if ($runtime == 'js' && $CFG->filter_poodll_html5controls == 'native') { $returnString = ""; //the $rtmp_file as it comes from assignment and questions, is urlencoded, we need to decode //or html 5 playback will fail Justin 20121016 $rtmp_file = urldecode($rtmp_file); //figure out the mime type by the extension $mime = ""; switch ($ext) { case "mov": case "mp4": $mime = "video/mp4"; break; case "3gp": $mime = "video/3gpp"; break; case "3g2": $mime = "video/3gpp2"; break; case "ebm": $mime = "video/webm"; break; default: $mime = "video/mp4"; } //The HTML5 Code (can be used on its own OR with the mediaelement code below it $returnString .= "<audio controls width='" . $width . "' height='" . $height . "'>\n <source type='" . $mime . "' src='" . $rtmp_file . "'/>\n </audio>"; //if we are using SWF } else { //Flowplayer if ($useplayer == "fp" || $CFG->filter_poodll_html5controls == "js") { $returnString = self::fetchFlowPlayerCode($width, $height, $rtmp_file, "audio", $ismobile, "", false, $splashurl); //JW player } else { if ($useplayer == "jw") { $flashvars = array(); $flashvars['file'] = $rtmp_file; $flashvars['autostart'] = 'false'; $returnString = self::fetchSWFObjectWidgetCode('jwplayer.swf', $flashvars, $width, $height, '#FFFFFF'); //if the file is an mp3, and we are using poodll player, don't handle it //either pass it to multi media plugin filter or pass it flowplayer // PoodLL player can't mp3 without RTMP } else { if (substr($rtmp_file, -4) == '.mp3') { $returnString = self::fetchFlowPlayerCode($width, $height, $rtmp_file, "audio", $ismobile); //$returnString= "<a href=\"$rtmp_file\">$rtmp_file</a>"; //PoodLL Player } else { $returnString = self::fetchSWFWidgetCode('poodllaudioplayer.lzx.swf9.swf', $params, $width, $height, '#FFFFFF'); } } } //regardless of swf player, add a download icon if appropriate $context = \context_course::instance($COURSE->id); $has_permission = has_capability('filter/poodll:candownloadmedia', $context); if ($CFG->filter_poodll_download_media_ok && $has_permission) { $returnString .= "<a class='filter_poodll_bt_dl' href='" . urldecode($rtmp_file) . "'>" . " <img src='" . $CFG->{'wwwroot'} . "/filter/poodll/pix/download.png' class='filter_poodll_bt_dl_icon' alt='download' />" . "</a><div></div>"; } } $renderer = $PAGE->get_renderer('filter_poodll'); return $renderer->fetchAudioPlayer($returnString); }
function fetchSimpleAudioPlayer($rtmp_file, $protocol = "", $width = "450", $height = "40", $embed = false, $embedstring = "Play") { global $CFG, $USER, $COURSE; //Set our servername . $flvserver = $CFG->poodll_media_server; //Set our use protocol type //if one was not passed, then it may have been tagged to the url //this was the old way. if ($protocol == "") { $type = "rtmp"; if (strlen($rtmp_file) > 5) { $protocol = substr($rtmp_file, 0, 5); switch ($protocol) { case "yutu:": $rtmp_file = substr($rtmp_file, 5); $rtmp_file = getYoutubeLink($rtmp_file); $type = "http"; break; case "http:": $rtmp_file = substr($rtmp_file, 5); $type = "http"; break; case "rtmp:": $rtmp_file = substr($rtmp_file, 5); default: $type = "rtmp"; } } //end of if strlen(rtmpfile) > 4 //If we have one passed in, lets set it to our type } else { switch ($protocol) { case "yutu": $rtmp_file = getYoutubeLink($rtmp_file); $type = "http"; break; case "http": case "rtmp": default: $type = $protocol; } } //Add course id and full path to url if necessary if ($protocol != "yutu") { //If we are using course id's add one to this file if ($CFG->filter_poodll_usecourseid) { $rtmp_file = $COURSE->id . "/" . $rtmp_file; } //If we are http and not youtube, lets set the full path if ($type == 'http') { $rtmp_file = $CFG->wwwroot . "/file.php/" . $rtmp_file; } } //some common variables for the embedding stage. $playerLoc = $CFG->wwwroot . '/filter/poodll/flash/poodllaudioplayer.lzx.swf9.swf'; //If we want to avoid javascript we do it this way //embedding via javascript screws updating the entry on the page, //which is seen after marking a single audio assignment from a list if ($embed) { $lzid = "lzapp_audioplayer_" . rand(100000, 999999); $returnString = "\t\t\n\t\t <div id='{$lzid}' class='player'>\n <a href='#' onclick=\"javascript:loadAudioPlayer('{$rtmp_file}', '{$lzid}', 'sample_{$lzid}', '{$width}', '{$height}'); return false;\">{$embedstring} </a>\n </div>\t\t\n\t\t"; /* $flashvars='red5url='.urlencode($flvserver).'&playertype=' . $type . '&mediapath='.$rtmp_file.'&lzproxied=false'; $returnString = "<embed src='$playerLoc' width='$width' height='$height' bgcolor='#ffffff' allowscriptaccess='always' allowfullscreen='false' flashvars='$flashvars' />"; */ return $returnString; //if we do not want to use embedding, ie use javascript to detect and insert (probably best..?) } else { $returnString = " <table><tr><td>\n\t <script type=\\'text/javascript\\'>\n\t lzOptions = { ServerRoot: \\'\\'};\n\t </script>\n\t <script type=\"text/javascript\" src=\"{$CFG->wwwroot}/filter/poodll/flash/embed-compressed.js\"></script>\n\t <script type=\"text/javascript\">\n\t" . ' lz.embed.swf({url: \'' . $playerLoc . '?red5url=' . urlencode($flvserver) . '&playertype=' . $type . '&mediapath=' . $rtmp_file . '&lzproxied=false\', bgcolor: \'#ffffff\', width: \'' . $width . '\', height: \'' . $height . '\', id: \'lzapp_audioplayer_' . rand(100000, 999999) . '_ap\' , accessible: \'false\'}); ' . "\n\t </script>\n\t <noscript>\n\t Please enable JavaScript in order to use this application.\n\t </noscript>\n\t </td></tr>\n\t\t\t<tr><td></td></tr></table>"; } return $returnString; }