HTML5 VIDEO无法在我的rails 3应用中运行

[英]HTML5 VIDEO is not working in my rails 3 app


I am trying to display HTML5 video in my Rails 3 app in development,i am using Sqlite3 and default webserver(Webrick).I put the video file (movie.ogg) under assets (assets/movie.ogg).The video window screen shows up but there is no video on there though.I have 3 questions...Since rails app assets doesn't have sub-folder for video(as the way it has images),where do you put video files? Does Webrick support Html5 video?Here is my code below ,what am i missing here,to make the video work?

我正在尝试在开发中的Rails 3应用程序中显示HTML5视频,我正在使用Sqlite3和默认网络服务器(Webrick)。我将视频文件(movie.ogg)放在资产(assets / movie.ogg)下。视频窗口屏幕显示但是那里没有视频。我有3个问题...由于rails app资产没有视频子文件夹(就像它有图像的方式),你在哪里放视频文件? Webrick是否支持Html5视频?以下是我的代码,我在这里缺少什么才能使视频正常工作?

view

       <video width="320" height="240" controls="controls">
       <source src="/assets/movie.mp4" type="video/mp4" />
       <source src="/assets/movie.ogg" type="video/ogg" />
       <source src="/assets/movie.webm" type="video/webm" />
         Your browser does not support the video tag.
       </video>

config/initializers/mime_types.rb

  Rack::Mime::MIME_TYPES.merge!({
  ".ogg"     => "application/ogg",
  ".ogx"     => "application/ogg",
  ".ogv"     => "video/ogg",
  ".oga"     => "audio/ogg",
  ".mp4"     => "video/mp4",
  ".m4v"     => "video/mp4",
  ".mp3"     => "audio/mpeg",
  ".m4a"     => "audio/mpeg"
})

4 个解决方案

#1


10  

The video_tag helper builds an HTML 5 <video> tag.

video_tag帮助程序构建HTML 5

By default, files are loaded from public/videos. To load from assets/video add the following line to your config/application.rb file:

默认情况下,文件是从公共/视频加载的。要从资源/视频加载,请将以下行添加到config / application.rb文件中:

config.assets.paths << "#{Rails.root}/app/assets/videos"

Tag Usage:

<%= video_tag (["movie.mp4", "movie.ogg", "movie.webm"] :size => "320x240", :controls => true, :autobuffer => true) %>

#2


4  

The assets pipeline is used for static assets. If you're adding video files to your app often, you should put them somewhere else (for example, public/videos or public/system/videos). If they really are static assets, try restarting your server first.

资产管道用于静态资产。如果您经常将视频文件添加到应用中,则应将其放在其他位置(例如,公共/视频或公共/系统/视频)。如果它们确实是静态资产,请尝试首先重新启动服务器。

#3


2  

Assuming your html is correct, unless things have dramatically changed in rails 3.1 with the asset pipeline anything contained in the public folder can be served up from the web server, so the exact location of where to store videos is up to you. According to your sources above you should put your videos in public/assets then confirm the videos are being served up by accessing http://localhost:3000/assets/movie.mp4 (or any other src url for a video).

假设您的html是正确的,除非在rails 3.1中使用资产管道发生显着变化,公共文件夹中包含的任何内容都可以从Web服务器提供,因此存储视频的确切位置取决于您。根据您上面的消息来源,您应该将您的视频放在公共/资产中,然后通过访问http:// localhost:3000 / assets / movie.mp4(或视频的任何其他src网址)确认视频正在提供。

#4


0  

To serve videos as static assets in Rails 4, the best way is to use the video tag:

要在Rails 4中将视频作为静态资源提供,最好的方法是使用视频标记:

Simply create a folder in 'assets' called 'videos' and store your videos there:

只需在“资产”中创建一个名为“视频”的文件夹,然后将视频存储在那里:

app/assets/videos/mycoolvideo.mp4

Then in your views:

然后在你的意见:

<%= video_tag "mycoolvideo.mp4" %>

If you need to specify size, a poster image or add controls, add (but this is HTML, not Rails):

如果您需要指定大小,海报图片或添加控件,请添加(但这是HTML,而不是Rails):

<%= video_tag "mycoolvideo.mp4", width: "640", height: "480", poster: "mycoolvideo.jpg", controls: true %>

Note that Rails cleverly knows that the image is in the image folder, so specifying a name is enough, without adding images/ or assets/images/ before the image name.

请注意,Rails巧妙地知道图像位于图像文件夹中,因此指定名称就足够了,而无需在图像名称之前添加图像/或assets / images /。

If you want to pass in many videos (or better said, the same video in different formats), pass an array:

如果你想传入许多视频(或更好地说,不同格式的同一视频),传递一个数组:

<%= video_tag ["mycoolvideo.mp4", "mycoolvideo.ogg", "mycoolvideo.webm"], size: "620x480", controls: true %>

Note that for sizing you can either use size: "widthxheight" ("640x360") or separately height: and width:

请注意,对于尺寸调整,您可以使用尺寸:“widthxheight”(“640x360”)或单独使用尺寸:和宽度:


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2012/01/13/7310027b58394e4327f6274222f68ae2.html



猜您在找
Safari未在Rails应用中加载HTML5视频 - Safari not loading HTML5 video in Rails app 在简单的rails应用中使用HTML5视频标签 - using HTML5 video tag in a simple rails app AngularJS无法在我的SF2应用程序中运行 - AngularJS not working in my SF2 app 我的Rails 3应用程序中的Metric-fu将无法运行 - Metric-fu in my Rails 3 app won't run 为什么jQuery不能在我的rails 5应用程序中工作? - Why is jQuery not working in my rails 5 app? Html5离线应用程序,角度无法脱机工作 - Html5 Offline app with angular not working offline Javascript无法在Rails应用页面中工作 - Javascript not Working in Rails app page Google地方信息自动填充在Rails应用上无法正常运行 - Google Places autocomplete on a Rails app not working reliably
相关教程
【No1】HTML5教程从入门到精通及网站源码下载 【No174】李兴华系列之Java8、Oracle、JavaScript、HTML5、Spring、Struts、Hibernate系列视频教程下载 【No199】2018年最新尚硅谷全套Java、Android、HTML5前端视频教程下载 【No31】李炎恢老师HTML5+CSS3教程与课件代码【共享完毕】下载 【No97】Spring+SpringMVC+MyBatis开发外卖app后台完整项目教程 【No217】kotlin高级教程从零开始开发完整安卓商城app 【No237】Vue2.5开发去旅游网站App 从零基础入门到实战项目 【No289】Android高级开发教程实战开发内涵段子APP视频教程下载
 
© 2014-2018 ITdaan.com 粤ICP备14056181号