How to use Wordpress audio player (standalone version) with jQuery and jQuery SWFObject (progressive enhancement).
HTML
<a class="audio" href="audio/reason.mp3"> Audio: An Electronic Reason </a>
Javascript
$('.audio').each(function(){ audio_file = $(this).attr('href'); $(this).flash( { swf: 'flash/audioplayer.swf', flashvars: { soundFile: audio_file } } ); });
Javascript
// close other audio players // called by audio player when click on play button function ap_stopAll(player_id) { $('.audio').each(function(){ if($(this).attr('href') != player_id) { $(this).find('object')[0].SetVariable("closePlayer", 1); } else { $(this).find('object')[0].SetVariable("closePlayer", 0); } }); } $(document).ready(function() { $('.audio').each(function(){ audio_file = $(this).attr('href'); $(this).flash( { swf: 'flash/audioplayer.swf', flashvars: { playerID: "'" + audio_file + "'", soundFile: audio_file } } ); }); });
How it works:
ap_stopAll() with its id as parameterHTML
<p> <a class="audio" href="audio/reason.mp3" id="reason"> Audio: An Electronic Reason </a> </p> <p> <a class="audio" href="audio/sunday.mp3" id="sunday"> Audio: By Sunday Afternoon </a> </p>
Javascript
// close other audio players // called by audio player when click on play button function ap_stopAll(player_id) { $('.audio_flash').each(function(){ if($(this).attr('id') != player_id) { $(this).find('object')[0].SetVariable("closePlayer", 1); } else { $(this).find('object')[0].SetVariable("closePlayer", 0); } }); } $(document).ready(function() { $('.audio').each(function() { audio_file = $(this).attr('href'); audio_title = $(this).text(); audio_id = $(this).attr('id'); div = $('<div class="audio_flash" id="' + audio_id + '"></div>'); $(this).after(div); $(this).after(audio_title); $(this).remove(); div.flash( { swf: 'flash/audioplayer.swf', flashvars: { soundFile: audio_file, playerID: "'" + audio_id + "'", quality: 'high', lefticon: '0xFFFFFF', righticon: '0xFFFFFF', leftbg: '0x357CCE', rightbg: '0x32BD63', rightbghover: '0x2C9D54', wmode: 'transparent' }, height: 50 } ); }); });