Javascript

Using Jquery to Replace an mp3 Link with a Flash Audio Player

The Javascript code below uses jQuery to convert mp3 links to a flash player on the fly. It utilizes this flash player: http://flash-mp3-player.net.

 

<script type='text/javascript'>
 
$('#main a').each(function(){
 
if($(this).attr('href')!=undefined){
 
match=$(this).attr('href').match(/\.(mp3)/);
 
if(match!=null){
href=$(this).attr('href');
text=$(this).text();
 
player=
'<p style="margin-top:20px;">'+text+'</p>'+
'<object type="application/x-shockwave-flash" data="http://flash-mp3-player.net/medias/player_mp3_mini.swf" width="200" height="20">'+
'<param name="movie" value="http://flash-mp3-player.net/medias/player_mp3_mini.swf" />'+
'<param name="bgcolor" value="#000000" />'+
'<param name="FlashVars" value="mp3='+href+'&amp;loadingcolor=AD0E1D&amp;buttoncolor=AD0E1D&amp;slidercolor=AD0E1D" />'+
'</object>';
 
p=$(this).parent();
$(this).remove();
$(p).append(player);
}
 
}
 
});
 
</script>

 

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.