Ways to stream audio (mp3/wav/etc)...Gem/Plugins vs HTML5?
I have a rails app that is coming along nicely...I would like to give the users the ability to upload and stream uploaded mp3s.
Currently I'm uploading to Amazon S3 through Paperclip with my site hosted on heroku.
I can upload the mp3s perfectly fine, so now I'm just looking for a way to support the playing of the actual files.
Are there any good gems/plugins that work with this issue that someone has used before?
Should I just go ahead and try to figure out how to do it with HTML5?
Anyone suggestions or opinions?
I would just use HTML5 and jquery, seems to be the most straightforward approach.
add gem 'jquery-rails', '>= 1.0.3' to your Gemfile and run 'bundle install'
Then add some markup in your views to give the divs and links for playing songs an id and class name. In this case the div/section id is "song" and the classname for the link is "play_song".
<h2>Listen to Song</h2>
<section id="song">
</section>
<td><%= link_to "HTML5 Audio", download_url_for(song.key), :class => "play_song" %></td>
Then in your js file:
$(document).ready(function() {
var audioSection = $('section#song');
$('a.play_song').click(function() {
var audio = $('<audio>', {
controls : 'controls'
});
var url = $(this).attr('href');
$('<source>').attr('src', url).appendTo(audio);
audioSection.html(audio);
return false; });
});
链接地址: http://www.djcxy.com/p/52468.html