Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Load the page with just a direct download to the audio file. Detect if the browser supports MP3s. If it does, progressively enhance the direct download into an AUDIO tag. Here's a sample:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Audio demo&lt;/title&gt; &lt;script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.0.6/modernizr.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p id="audio"&gt; &lt;a href="BadAppleEnglish.mp3"&gt;Listen &amp;raquo;&lt;/a&gt; &lt;/p&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"&gt;&lt;/script&gt; &lt;script src="audio.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And the Javascript:</p> <pre><code>$(function () { var audioElement = $('#audio'), href = audioElement.children('a').attr('href'); $.template('audioTemplate', '&lt;audio src="${src}" controls&gt;'); if (Modernizr.audio.mp3) { audioElement.empty(); $.tmpl('audioTemplate', {src: href}).appendTo(audioElement); } }); </code></pre> <p>I would imagine that most of the zillions of prebuilt MP3 playing plugins work like this.</p> <p>UPDATE:</p> <p>Since you've edited the question to specify that you'd prefer a solution that doesn't use jQuery, I will point out that rewriting this to not use jQuery is trivial. It's just longer and less elegant. Do keep in mind that Javascript libraries loaded from CDNs are usually cached by the browser.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload