Reputation: 2174
I'm having some trouble getting a specific mp3 that i've uploaded to play.
I have a Ruby on Rails app and I'm using paperclip to upload the actual mp3. I'm using a Javascript library (called jp-player). I'm at the point where I know the mp3 file has been uploaded, but i'm not getting it to officially play. If I hit the play
button, nothing happens.
My model looks like this:
has_attached_file :mp3
validates_attachment :mp3, :content_type => { :content_type => ["audio/mpeg", "audio/mp3"] }, :file_name => { :matches => [/mp3\Z/] }
My controller looks like
def create
@cafe = current_user.cafes.build(cafe_params)
if @cafe.save
redirect_to @cafe
else
render 'new'
end
end
def cafe_params
params.require(:cafe).permit(:name, :description, :street_address, :state, :editors_note, :website, :image, :mp3)
end
My view (I have this as a partial that i'm calling in a different view)
#cafe_content
#jquery_jplayer_1.jp-jplayer
#jp_container_1.jp-audio
.jp-type-single
.jp-gui.jp-interface
%ul.jp-controls
%li
%a.jp-play{:href => "javascript:;", :tabindex => "1"}
%li
%a.jp-pause{:href => "javascript:;", :tabindex => "1"}
%li
%a.jp-mute{:href => "javascript:;", :tabindex => "1", :title => "mute"}
%li
%a.jp-unmute{:href => "javascript:;", :tabindex => "1", :title => "unmute"}
.jp-progress
.jp-seek-bar
.jp-play-bar
.jp-time-holder
.jp-current-time
.jp-volume-bar
.jp-volume-bar-value
.jp-no-solution
%span Update Required
To play the media you will need to either update your browser to a recent version or update your
= succeed "." do
%a{:href => "http://get.adobe.com/flashplayer/", :target => "_blank"} Flash plugin
:javascript
$(document).ready(function(){
$("#jquery_jplayer_1").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
mp3: "<%= @cafe.mp3.url %>",
});
},
swfPath: "/js",
supplied: "mp3"
});
});
Does anyone know if there is anything that I am missing that could get this to properly run?
Upvotes: 0
Views: 150
Reputation: 646
May be your jp player seeks for absolute path, Instead
<%= @cafe.mp3.url %>
Try this
<%= URI.join(request.url, @cafe.mp3.url) %>
in your mp3 path,
Upvotes: 2