summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2009-06-17 11:16:44 +0400
committerAndrew Dolgov <[email protected]>2009-06-17 11:16:44 +0400
commit95f67d2ebcb367bc5d06b802bdffb5642dac8f81 (patch)
tree92ea9f758d30936497a18db586b4109f236b9760
parent70c9b173145a9f3cb74f681afcc4dee9e1a2314d (diff)
add support for HTML5 way of playing audio/video enclosures (closes #246)
-rw-r--r--functions.js29
-rw-r--r--functions.php40
-rw-r--r--viewfeed.js4
3 files changed, 62 insertions, 11 deletions
diff --git a/functions.js b/functions.js
index 4aa5486a3..5c1b26a59 100644
--- a/functions.js
+++ b/functions.js
@@ -2133,3 +2133,32 @@ function truncate_string(s, length) {
if (s.length > length) tmp += "&hellip;";
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'));
+ }
+ }
+}
diff --git a/functions.php b/functions.php
index c89f11a13..6a8e85628 100644
--- a/functions.php
+++ b/functions.php
@@ -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) . "\">" .
diff --git a/viewfeed.js b/viewfeed.js
index 6afc6c317..7e53467dc 100644
--- a/viewfeed.js
+++ b/viewfeed.js
@@ -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);