Adding "clickable" individual .mp3 files to page?

The following code pasted into the head of the page will embed media player. Width and height are set to 0 so it is hidden.

<script type="text/javascript">
function play(media){
document.getElementById('mediaplayer').innerHTML='<object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95"'
+'type="application/x-oleobject" width="0" height="0"><param name="fileName" value="'+media+'">'
+'<embed type="application/x-mplayer2" src="'+media+'" width="0" height="0"><\/embed><\/object>'
}
</script>

Then in the body add links for each music source and add some styles with CSS. (Writing a fake url with a legitimate file extension for media player will serve as a stop funtion). Add an empty div at the bottom of your page with the id matching the javascript getElementById to serve as refrence for the javascript code.

<ul>
<li><a onclick="play(this.href);return false" href="SOURCE 1">1</a></li>
<li><a onclick="play(this.href);return false" href="SOURCE 2">2</a></li>
<li><a onclick="play(this.href);return false" href="SOURCE 3">3</a></li>
<li><a onclick="play(this.href);return false" href="stop.m3u">X</a></li>
</ul>

<div id="mediaplayer"></div>

To stream mp3s, create a file in your html editor, insert the url where your mp3 file is stored (for example: http://www.yoursite.com/sound/music.mp3) and save this file with an .m3u extension (somename.m3u) Repeat for each mp3 giving each a unique name. Upload these files to the directory where your mp3s are stored. Insert the URL for these files (not the mp3s) into your links.

As for preventing people downloading them, there is no surefire way. Your best bet is to use low quality samples that will entice people to want to hear more and buy the CD rather than using the full length high quality version.

Nhận xét

Bài đăng phổ biến từ blog này

Ký tự viết tắt trong chat & email

dung lượng RAM lớn nhất mà HĐH cấu trúc 32-bit nhận được

Ubuntu LAMP Server