]> git.wh0rd.org Git - tt-rss.git/commitdiff
add support for HTML5 way of playing audio/video enclosures (closes #246)
authorAndrew Dolgov <fox@bah.org.ru>
Wed, 17 Jun 2009 07:16:44 +0000 (11:16 +0400)
committerAndrew Dolgov <fox@bah.org.ru>
Wed, 17 Jun 2009 07:16:44 +0000 (11:16 +0400)
functions.js
functions.php
viewfeed.js

index 4aa5486a3c1a656372d6d52ed3b67173aee3a205..5c1b26a5951ebc41cb73317a91f53be6b7ab44da 100644 (file)
@@ -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'));
+               }
+       }
+}
index c89f11a1343b2ae1d8b2b7f6083cd3ccf31c7bbe..6a8e8562820a958cfb469b431e85df58a34a0b05 100644 (file)
 
                                        $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) . "\">" .
 
                                        $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) . "\">" .
index 6afc6c317452acfdcd3c42a134a7f158387ca47b..7e53467dc5a5156ded208685fb11f7c9ec176a9f 100644 (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);