From c3edc667f127b9e36ecc08eb790f6c754e413e8f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 30 Nov 2010 12:40:23 +0300 Subject: use html5 audio player instead of flash when possible --- functions.php | 42 +++++++++++++++++++++++++++++++++--------- modules/backend-rpc.php | 3 +++ tt-rss.css | 21 +++++++++++++++++++++ tt-rss.js | 4 +++- viewfeed.js | 28 ++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 10 deletions(-) diff --git a/functions.php b/functions.php index 175817892..90e23d897 100644 --- a/functions.php +++ b/functions.php @@ -4463,14 +4463,38 @@ $entry = ""; - if ($ctype == "audio/mpeg") { - - $entry .= " - "; + if (strpos($ctype, "audio/") === 0) { + + if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false || + strpos($_SERVER['HTTP_USER_AGENT'], "Chrome") !== false || + strpos($_SERVER['HTTP_USER_AGENT'], "Safari") !== false )) { + + $id = 'AUDIO-' . uniqid(); + + $entry .= ""; + + $entry .= "".__("Play").""; + + } else { + + $entry .= " + + "; + } } + $filename = substr($url, strrpos($url, "/")+1); + + $entry .= " " . + $filename . " (" . $ctype . ")" . ""; + return $entry; } @@ -6792,12 +6816,12 @@ if (!$ctype) $ctype = __("unknown type"); - $filename = substr($url, strrpos($url, "/")+1); +# $filename = substr($url, strrpos($url, "/")+1); $entry = format_inline_player($link, $url, $ctype); - $entry .= " " . - $filename . " (" . $ctype . ")" . ""; +# $entry .= " " . +# $filename . " (" . $ctype . ")" . ""; array_push($entries_html, $entry); diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 239ff60f6..1447634bf 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -307,6 +307,9 @@ // XML method if ($subop == "sanityCheck") { + + $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true"; + print ""; if (sanity_check($link)) { print ""; diff --git a/tt-rss.css b/tt-rss.css index d8b92e5ab..a5662fede 100644 --- a/tt-rss.css +++ b/tt-rss.css @@ -1652,4 +1652,25 @@ a.bookmarklet { top : -1px; } +.player { + display : inline-block; + color : gray; + font-size : 11px; + font-family : sans-serif; + border : 1px solid gray; + padding : 0px 4px 0px 4px; + margin : 0px 2px 0px 2px; + width : 50px; + text-align : center; + background : white; +} +.player.playing { + color : #00c000; + border-color : #00c000; +} + +.player:hover { + background : #f0f0f0; + cursor : pointer; +} diff --git a/tt-rss.js b/tt-rss.js index fef3066f3..d619c4c02 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -318,8 +318,10 @@ function init() { loading_set_progress(20); + var hasAudio = !!((myAudioTag = document.createElement('audio')).canPlayType); + new Ajax.Request("backend.php", { - parameters: {op: "rpc", subop: "sanityCheck"}, + parameters: {op: "rpc", subop: "sanityCheck", hasAudio: hasAudio}, onComplete: function(transport) { backend_sanity_check_callback(transport); } }); diff --git a/viewfeed.js b/viewfeed.js index 5d40fb321..4444ce29d 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -2365,3 +2365,31 @@ function editArticleNote(id) { exception_error("editArticleNote", e); } } + +function player(elem) { + var aid = elem.getAttribute("audio-id"); + var status = elem.getAttribute("status"); + + var audio = $(aid); + + if (audio) { + if (status == 0) { + audio.play(); + status = 1; + elem.innerHTML = __("Playing..."); + elem.title = __("Click to pause"); + elem.addClassName("playing"); + } else { + audio.pause(); + status = 0; + elem.innerHTML = __("Play"); + elem.title = __("Click to play"); + elem.removeClassName("playing"); + } + + elem.setAttribute("status", status); + } else { + alert("Your browser doesn't seem to support HTML5 audio."); + } +} + -- cgit v1.2.3