我在获取已上传的特定 mp3 进行播放时遇到一些问题。
我有一个 Ruby on Rails 应用程序,我正在使用回形针上传实际的 mp3。我正在使用 Javascript 库(称为 jp-player)。我现在知道 mp3 文件已上传,但我还没有让它正式播放。如果我点击播放
按钮,什么也不会发生。
我的模型如下所示:
has_attached_file :mp3
validates_attachment :mp3, :content_type => { :content_type => ["audio/mpeg", "audio/mp3"] }, :file_name => { :matches => [/mp3\Z/] }
我的 Controller 看起来像
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
我的 View (我将此作为我在不同 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"
});
});
有谁知道我是否缺少任何东西可以使其正常运行?
最佳答案
可能是你的 jp 玩家寻求的是绝对路径,而不是
<%= @cafe.mp3.url %>
试试这个
<%= URI.join(request.url, @cafe.mp3.url) %>
在你的 mp3 路径中,
关于javascript - 使用回形针 gem 上传 mp3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45178145/