Playing MP3's through rails ?

I have been trying to figure out the best way to serve music mp3's If I do mysite.com/audio/mysong.mp3 it seems to play the song, but sometimes a dialog comes up asking if you want to save the file when the user clicks the link. That depends on the browser. I don't want to do that, I just want the song to play.

If I set up a partial template like below. That seems to work on the first load. But when I render the partial a second time with a different song. The first song is still playing and the new song starts playing as well so there are 2 songs playing at the same time. I've looked into how to do send_file()/send_data() and so on, not sure on that, but I suspect it may work the same as the other method above ? for that I found this, but I haven't figured it out: http:// www.ruby-forum.com/topic/61437

Here's the templat I have that is partialy rendered:

<OBJECT width='300' height='42'> <param name='SRC' value=<%= "'/public/audio/#{@song}'>" %> <param name='AUTOPLAY' VALUE='true'> <param name='CONTROLLER' VALUE='FALSE'>

<EMBED SRC=<%="'/audio/#{@song}' HIDDEN AUTOSTART='TRUE' LOOP='FALSE' WIDTH='0' HEIGHT='0' CONTROLLER='FALSE' " %>

BGCOLOR='#FF9900'></EMBED> </OBJECT>

While I'm at it, is there any way to have an mp3 keep playing a song when you render a new page ?

Thanks

For God’s [and the user’s] sake, please don’t play media on the user’s computer without the user’s explicit request. Remember the mid-late 90’s midi embedded web sites? Oh, the nightmares this is gonna give me.

RSL

I somewhat agree with Russell on this, however for some sites it can make sense to do this.

The issue isn’t specific to Rails, you would use the same techniques as elsewhere. For instance you can have a frame that stays active or you can of course pop a new window to hold this. Either of those methods would allow you to continue playing between page transitions. Both have their own disadvantages (framesets and popup windows blocking).

Remember to provide an option for users to silence the sound and note that many users might visit your site at work (where sound isn’t necessarily a desirable thing). It is so frustrating when sites don’t give you the option of turning that off.

Blessings,

Jeff

You'll need to use a player to play the file. Your best bet is one constructed in flash. Then you can give the user controls for muting audio or adjusting volume.

M<><

Thanks,

I've played around with this and have had a number of problems with firefox as well as other issues. It does look interesting, but my song will also show up in the html, so it doesn't prevent anyone from stealing the music any different if I used some other method I'm guessing. At this time I am probably going to try a simpler approach for now I guess.