Friday, April 1, 2011

Playing music file from HTML page

This is first time I need this in many years, but finally this day has come: I need to play MP3 file from web page.
Looks like the easiest way to do is by using embed tag, so when I need it is needed to play it, I just call from javascript:
$('#sound_element').html("<embed src='scripts/"+file+".mp3' hidden='true' autostart='true' loop='false'>");
Of course I need to have this div somewhere on the page:
<div id="sound_element"></div>
And it does the magic. I found that it plays flawlessly in Chrome, but for Firefox it asks for Quicktime plugin. But I need it for managed environment, so it is not a big deal.
Finally, I can add some tunes to my blog! ;)

No comments:

Post a Comment