add support for HTML5 way of playing audio/video enclosures (closes #246)

This commit is contained in:
Andrew Dolgov 2009-06-17 11:16:44 +04:00
parent 70c9b17314
commit 95f67d2ebc
3 changed files with 62 additions and 11 deletions

View File

@ -2133,3 +2133,32 @@ function truncate_string(s, length) {
if (s.length > length) tmp += "…";
return tmp;
}
function switchToFlash(e) {
var targ = e;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
//targ is the link that was clicked
var audioTag=targ;
do {
audioTag=audioTag.previousSibling;
} while(audioTag && audioTag.nodeType != 1)
var flashPlayer = audioTag.getElementsByTagName('div')[0];
targ.parentNode.insertBefore(flashPlayer,targ);
targ.parentNode.removeChild(targ);
audioTag.parentNode.removeChild(audioTag);
return false;
}
function html5AudioOrFlash(type) {
var audioTag = document.createElement('audio');
if(! audioTag.canPlayType || audioTag.canPlayType(type)=="no"){
if($('switchToFlashLink')){
switchToFlash($('switchToFlashLink'));
}
}
}

View File

@ -4692,11 +4692,21 @@
$entry = "";
if (($ctype == __("audio/mpeg")) &&
(get_pref($link, "ENABLE_FLASH_PLAYER")) ) {
$entry .= "<object type=\"application/x-shockwave-flash\" data=\"extras/button/musicplayer.swf?song_url=$url\" width=\"17\" height=\"17\"> <param name=\"movie\" value=\"extras/button/musicplayer.swf?song_url=$url\" /> </object> ";
if (substr($ctype,0,6)=="audio/" || $ctype=="application/ogg" || $ctype=="application/x-ogg") {
$entry .= "<audio controls=\"controls\"><source src=\"$url\" type=\"$ctype\" />";
if (($ctype == __("audio/mpeg")) &&
(get_pref($link, "ENABLE_FLASH_PLAYER")) ) {
$entry .= "<div><object type=\"application/x-shockwave-flash\" data=\"extras/button/musicplayer.swf?song_url=$url\" width=\"17\" height=\"17\"> <param name=\"movie\" value=\"extras/button/musicplayer.swf?song_url=$url\" /> </object></div>";
}
$entry .= "</audio>";
if (($ctype == __("audio/mpeg")) &&
(get_pref($link, "ENABLE_FLASH_PLAYER")) ) {
$entry .= "<a id='switchToFlashLink' href='#' onclick='return switchToFlash(this)'>".__('Switch to Flash Player')."</a><br />";
$entry .= "<script type='text/javascript'>html5AudioOrFlash('$ctype');</script>";
}
} elseif (substr($ctype,0,6)=="video/") {
$entry .= "<video controls=\"controls\"><source src=\"$url\" type=\"$ctype\" />";
$entry .= "</video>";
}
$entry .= "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
@ -5236,11 +5246,21 @@
$entry = "";
if (($ctype == __("audio/mpeg")) &&
(get_pref($link, "ENABLE_FLASH_PLAYER")) ) {
$entry .= "<object type=\"application/x-shockwave-flash\" data=\"extras/button/musicplayer.swf?song_url=$url\" width=\"17\" height=\"17\"> <param name=\"movie\" value=\"extras/button/musicplayer.swf?song_url=$url\" /> </object> ";
if (substr($ctype,0,6)=="audio/" || $ctype=="application/ogg" || $ctype=="application/x-ogg") {
$entry .= "<audio controls=\"controls\"><source src=\"$url\" type=\"$ctype\" />";
if (($ctype == __("audio/mpeg")) &&
(get_pref($link, "ENABLE_FLASH_PLAYER")) ) {
$entry .= "<div><object type=\"application/x-shockwave-flash\" data=\"extras/button/musicplayer.swf?song_url=$url\" width=\"17\" height=\"17\"> <param name=\"movie\" value=\"extras/button/musicplayer.swf?song_url=$url\" /> </object></div>";
}
$entry .= "</audio>";
if (($ctype == __("audio/mpeg")) &&
(get_pref($link, "ENABLE_FLASH_PLAYER")) ) {
$entry .= "<a id='switchToFlashLink' href='#' onclick='return switchToFlash(this)'>".__('Switch to Flash Player')."</a><br />";
$entry .= "<script type='text/javascript'>html5AudioOrFlash('$ctype');</script>";
}
} elseif (substr($ctype,0,6)=="video/") {
$entry .= "<video controls=\"controls\"><source src=\"$url\" type=\"$ctype\" />";
$entry .= "</video>";
}
$entry .= "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .

View File

@ -275,8 +275,10 @@ function render_article(article) {
try {
fi.scrollTop = 0;
} catch (e) { };
fi.innerHTML = article;
article.evalScripts();
} catch (e) {
exception_error("render_article", e);