Paperclip/MediaElement.js 播放器 gem 不工作
我正在尝试设置一个应用程序,可以在其中上传 .mp3 样本并播放它们。 Paul Irish 推荐了 MediaElementPlayer,因此我开始尝试使用它。我很高兴看到有一个 gem 可用(谢谢 Axel K.),但我似乎无法让它工作。
我已经包含了 gem,并且资产管道似乎正在加载所有内容,但是当页面加载时,每首歌曲都有一个播放器,但它在两端显示 0:00,当我按下播放时,没有任何反应。歌曲的路径也都是正确的。
这是我认为的代码:
<% @songs.each do |song| %>
<%= song.id %>: <%= song.title %><br/>
<audio id="player<%= song.id %>" src="<%= song.tune.path %>" type="<%= song.tune_content_type %>" controls="controls">
</audio>
<% end %>
<script>
$('audio').mediaelementplayer();
</script>
我直接从 MediaElementPlayer 站点示例复制了格式和音频标签(这可能是问题,但我不知道如何...)
也可能是导入的,我正在使用 Paperclip上传 .mp3。
**更新: 我只是将一首歌曲放入我的应用程序的公共文件夹中,并为其设置和音频标签,它就可以工作了。这让我觉得歌曲的上传方式有问题。但所有信息似乎都是正确的(路径、内容类型等......)...
I'm trying to setup an app where I can upload .mp3 samples and play them back. Paul Irish recommends MediaElementPlayer, so I've started futzing around with it. I happily see that there is a gem available (Thank you Axel K.), but I just can't seem to get it working.
I've included the gem, and the asset pipeline seems to be loading everything, but when the page loads, there is a player for each song, but it shows 0:00 on each end and when I press play, nothing happens. The path to the songs are all correct as well.
Here is the code from my view:
<% @songs.each do |song| %>
<%= song.id %>: <%= song.title %><br/>
<audio id="player<%= song.id %>" src="<%= song.tune.path %>" type="<%= song.tune_content_type %>" controls="controls">
</audio>
<% end %>
<script>
$('audio').mediaelementplayer();
</script>
I copied the format and the audio tags directly from the MediaElementPlayer site example (which could be the problem, but I'm not seeing how...)
Also potentially of import, I'm using Paperclip to upload the .mp3s.
**UPDATE:
I just dropped a song into a public folder of my app and setup and audio tag for it, and it works. This makes me think there is something wrong with the way that songs are being uploaded. But all the info seems to be correct (path, content-type, etc...)...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我完成并配置了 Amazon S3(这是我将在生产中使用的),一切都运行顺利。必须有一些关于文件本地存储位置或存储方式的信息,或者,哎呀,我不知道。但是设置 S3 并将剪辑存储在那里就像做梦一样。
So, I went through and just configured Amazon S3 (which is what I'll be using in production), and everything works without a hitch. There has to be something with where the file is stored locally, or how it's stored, or, heck, I don't know. But setting up S3 and storing the clips there works like a dream.