Playing music on my Web site

Actually, it’s my daughter’s Web site. I have an mp3 file that I’d like to let people hear–if they want! I’ve uploaded the .mp3 file to the site and created a link, but when I click the link, my computer complains that I don’t have enough memory to play the file. Apparently it’s trying to download the whole thing and then play it.

  1. The link opens a new page to play the song, I don’t want that, I want it to play in the background
  2. Is there a way to just send the bits along as they play? Is that “streaming”? How is it done?

I’m pretty HTML ignorant, so examples would be appreciated.

Ah, and I have permission from the artist to play this on the site, so leagal issues are not a concern, except that it would be nice if I could prevent visitors from downloading it.

Thanks!

Your best bet might be converting it into flash and using a pre-made flash MP3 player (with controls) to let it play.

Google “flash mp3 player” and look for one that is free and easy enough for you to use, and does what you want.

Googled ‘html website “streaming music”’ and got Wimpy.

Why not a simple embed, using Windows Media Player? This will work for most people.

Here’s some basic code:



<OBJECT ID="MediaPlayer" WIDTH="240" HEIGHT="42" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject">
<PARAM NAME="FileName" VALUE="yourfile.mp3">
<PARAM name="autostart" VALUE="false">
<PARAM name="ShowControls" VALUE="true">
<param name="ShowStatusBar" value="false">
<PARAM name="ShowDisplay" VALUE="false">
<EMBED TYPE="application/x-mplayer2" SRC="yourfile.mp3" NAME="MediaPlayer"
WIDTH="240" HEIGHT="42" ShowControls="1" ShowStatusBar="0" ShowDisplay="0" autostart="0"> </EMBED>
</OBJECT>

Where yourfile.mp3 is the song, and the mp3 file is in the same directory as the html page. If you move the mp3 to a different directory, you’ll have to change the relative url. Note that the player dimensions and the source file location are specified twice in this code. Make sure you have both.

Just copy the code into the appropriate place in your html. This will embed a small (240px x 42 px) Windows Media Player control bar in your page, with play, pause, stop etc. I think that if you want volume control on the player, you might have to make the width 320 instead of 240.

The instructions <PARAM name=“autostart” VALUE=“false”> and autostart=“0” means that the file will not automatically start playing. In order to start the song, the user will have to click the play button on the embedded player. That means that users can choose whether or not to hear the music.

As for preventing people from copying the song, that’s pretty much impossible. Even if you can prevent them from downloading or copying the actual digital file, there’s no way you can plug the analog hole. That is, as long as people can hear the song, they can use their sound card and a recording device to record it. As soon as you put sound on a web page, you’re pretty much conceding that anyone who really wants it is going to be able to download it.

Just wanted to note, also, that this is a bit disturbing.

If your computer doesn’t have enough memory to download and play an mp3 file, which i assume is only a few megabytes, it suggests a problem of some sort. How much RAM do you have? Are there heaps of other applications open?

Any computer less than about 6-8 years old should have plenty of memory for a simple task like this.

It’s a brand-new laptop with 2G memory running WinXP. I’m running two vmware machines (Linux and Win2K3 Server) with Oracle on Linux and Sybase on Win2K3–applications running against the DBs, of course. There was a memory bug that wouldn’t let me Hybernate, which suggests that the bug might have affected other applications than the go-to-sleep. I haven’t tried hitting the music link since I got the patch for the memory bug.

All non-geeks can WAKE UP NOW! The techno-geek speak is over. :slight_smile:
Thanks mhendo, I’ll give that a try and let you know what happens.

Works with IE, not with FireFox–any way to get a WMP plugin for Mozilla? I could put the instructions at the bottom of the page.

Thanks!!!

I think you’ll find that, once you put the html file and the mp3 on the server, it will work with Firefox.

Firefox has an issue with playing embedded files from a local hard drive. The problem is that it does not like relative urls. If you take the code that i gave you, and change the location of the mp3 to an absolute url (e.g. C:\My Documents\yourfile.mp3) i think you’ll find that it will work.

The funny thing is, though, that Firefox can deal with relative urls when it’s reading off the internet. It’s only on local hard drives that it has this problem. I had this problem myself a while ago, and it was driving me crazy until i went onto the Mozilla forums.

So, put the webpage and the mp3 up on the server, and test it out in Firefox. You might find that it works.

What would be the corresponding way to do this for Mac users with Safari or Firefox?

I’m assuming there’s not a universal way to call whatever MP3 playing app happens to be on a computer, but one of our design tenets is to be platform-agnostic.

The main concern is that Mac users are unlikely to have Windows Media Player, but they will have QuickTime.

I’d be able to live with “Windows users: Click this” and “Mac users: Click this” or is there a relatively simple way to sniff what they’ve got and present only the appropriate control?

This code should work for Quicktime:


<object height="50" width="200">
<param name="kioskmode" value="true">
<param name="src" value="yourfile.mp3">
<param name="autoplay" value="false">
<param name="controller" value="true">
<embed height="50" src="yourfile.mp3" type="video/quicktime" width="200" 

controller="true" autoplay="false" kioskmode="true">
</object>

In fact, given that most Windows users have Quicktime or Quicktime Alternative installed, this might actually be a better solution for broad compatibility than the Windows Media Player code offered earlier.

You RAWK! I’ll put them both there and let people choose.

The WMP version works dandy, but the Quicktime only plays about 4 seconds. I don’t think it’s the MP3, since it’s the same one that the Media Player plays all the way through. Any hints?

You’ve already helped so much that I hate to ask, but I’m stumped.

Here’s the page: Django’s Hope

Hmmm… Dunno, as the QT is playing just fine for me all the way through.

Win XP, IE 6, QT player 6.5.1 - not terribly up to date, but it’s our basic corporate setup.