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. -- Posted via http://www.ruby-forum.com/.
On 7/7/06, Andrew Kortina <rails@kortina.cjb.net> 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: http://musicplayer.sourceforge.net/ It seemed very nice and was easy enough to integrate with Rails. It may do just what you are looking for. HTH, Howard -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060708/ef04a11e/attachment.html
Andrew Kortina 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: <pre> 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" </pre> 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2/3/07, Andrew Kortina <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> data = f.sysread(100 * 1000) # only play the first 100 KB of the songA cosmetic suggestion: you can ditch the above comment if you change the line to: data = f.sysread(100.kilobytes) J. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---