On my site I’m allowing users to upload songs in mp3 format. Members
can download the full song, but on public pages I would like to use a
flash player to play a 30 second clip of the song and/or allow
downloading of a 30 second mp3 snippet. The songs are stored above the
web root directory, and I use the send_file method for the full file
downloads for members.
My question is, for the public view:
Is it possible to use the send_file method to send just the first X
seconds (or bytes) of a file?
If not, is there a way to crop the file somehow using a ruby script and
save something equivalent to a ‘thumbnail’ like we use for images?
Also, if anyone has any suggestions for a flash player to use to stream
mp3s I’d love to hear what they are.
On 7/7/06, Andrew K. [email protected] wrote:
Also, if anyone has any suggestions for a flash player to use to stream
mp3s I’d love to hear what they are.
a while back I fiddled with xspf Web Music Player:
It seemed very nice and was easy enough to integrate with Rails. It may
do
just what you are looking for.
HTH,
Howard
Andrew K. wrote:
On my site I’m allowing users to upload songs in mp3 format. Members
can download the full song, but on public pages I would like to use a
flash player to play a 30 second clip of the song and/or allow
downloading of a 30 second mp3 snippet. The songs are stored above the
web root directory, and I use the send_file method for the full file
downloads for members.
My question is, for the public view:
Is it possible to use the send_file method to send just the first X
seconds (or bytes) of a file?
If not, is there a way to crop the file somehow using a ruby script and
save something equivalent to a ‘thumbnail’ like we use for images?
Also, if anyone has any suggestions for a flash player to use to stream
mp3s I’d love to hear what they are.
Here’s what I did to solve this problem:
send the first 100KB of the song and then play it on the front end using
a flash player:
path = "/tmp/my_song.mp3"
f = File.new(path, "r")
data = f.sysread(100 * 1000) # only play the first 100 KB of the song
send_data data, :disposition => "inline", :type => "audio/mpeg",
:filename => "my_song.mp3"
This code goes in the controller of my rails app. If you don’t feed the
URL of the controller method into a flash player, this will just make
the first 100KB available as a file for download.
On 2/3/07, Andrew K. [email protected] wrote:
data = f.sysread(100 * 1000) # only play the first 100 KB of the song
A cosmetic suggestion: you can ditch the above comment if you change
the line to:
data = f.sysread(100.kilobytes)
J.