HTML5 Audio Player

October 26th, 2011 | by | tags:

HTML5 Logo from W3.orgTransom uses the WordPress Audio Player plugin, which, since it’s fashioned from Flash, is invisible to the iPhone/Pad/Pod-Touch. But Safari in all Apple’s iOSes is HTML5 <audio> aware, and supports MP3 play. So here’s our quick & filthy fix…

Open the file: /plugins/audio-player/audio-player.php.
Find the: function getPlayer().
Within that function, find the variable: $playerCode.
And insert this PHP/HTML (the $source var holds the URL of the MP3):

'<audio src="' . $source . '" controls>Flash stuff...</audio>'

So, where the original read:

$playerCode = '<p class="audioplayer_container"><span style="display:block;padding:5px;border:1px solid #dddddd;background:#f8f8f8" id="' . $playerElementID . '">' . sprintf(__('Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version <a href="%s" title="Download Adobe Flash Player">here</a>. You also need to have JavaScript enabled in your browser.', $this->textDomain), 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;promoid=BIOW') . '</span></p>';

It now says (we shortened the no-Flash text too):

$playerCode = '<p class="audioplayer_container"><span style="display:block;padding:5px;border:1px solid #dddddd;background:#f8f8f8" id="' . $playerElementID . '"><em>' . sprintf(__('<audio src="' . $source . '" controls><br />Audio player needs Flash9+ (<a href="%s" title="Download Adobe Flash Player">download</a>) and JavaScript.', $this->textDomain), 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW') . '</audio></em></span></p>';

‘Course, this is not a great way to do it:

  1. It needs redoing after every upgrade of this plugin.
  2. We should really should check first to see:
    1. Does browser supports the HTML5 audio tag? (IE8: no.)
    2. If so, will it play an mp3? (Firefox & Opera: no; Safari & Chrome: yes.)
  3. Then, according to above conditions, the script should:
    1. If yes to both, write only the HTML5 audio tag (w/ src), not the Flash stuff.
    2. If no to either, write only the Flash stuff, not the HTML5. (More info and scripts at HTML 5 Doctor.)

But at least now iPhoney/iFad folk can hear us.


4 Comments on “HTML5 Audio Player”

Leave a Reply