我在我的rails应用程序中使用MediaElement js插件用于视频播放器。它不适用于FLV格式视频。我收到类似这样的错误加载此资源时出错。我看到我写了我的代码它如何解决?
<video width="480" height="350" controls="controls" preload="none">
<!-- MP4 for Safari, IE9, iPhone, iPad, Android, and Windows Phone 7 -->
<source type="video/mp4" src="<%= @featured_video.asset.url %>" />
<!-- WebM/VP8 for Firefox4, Opera, and Chrome -->
<source type="video/webm" src="<%= @featured_video.asset.url %>" />
<!-- Ogg/Vorbis for older Firefox and Opera versions -->
<source type="video/ogg" src="<%= @featured_video.asset.url %>" />
Here I tried both format video/flv,video/x-flv but it is not working
<source type="video/flv" src="<%= @featured_video.asset.url %>" />
or
<source type="video/x-flv" src="<%= @featured_video.asset.url %>" />
<!-- Flash fallback for non-HTML5 browsers without JavaScript -->
<object width="320" height="240" type="application/x-shockwave-flash" data="<%= Rails.root %>/app/assets/javascripts/swf/flashmediaelement.swf">
<param name="movie" value="<%= Rails.root %>/app/assets/javascripts/swf/flashmediaelement.swf" />
<param name="flashvars" value="controls=true&file= <%= @featured_video.asset.url %>" />
</object>
</video>
答案 0 :(得分:0)
播放HTML5视频我喜欢使用videojs_rails gem
这很容易设置你需要做的就是:
1)将宝石放入宝石文件
gem 'videojs_rails'
2)将资源添加到application.js文件
# app/assets/javascripts/application.js
//= require video
3)该资源到application.css文件
/*
*= require video-js
*= require_self
*/
4)确保文件在资产管道中加载
#config/initializers/assets.rb
Rails.application.config.assets.precompile += %w( video-js.swf vjs.eot vjs.svg vjs.ttf vjs.woff )
现在在你看来你所要做的就是
<%= videojs_rails sources: { mp4: @featured_video.asset.ur, webm: @featured_video.asset.ur}, setup: "{}", controls: false, width:"400" %>
我希望这会有所帮助。
快乐黑客