I am trying to get videojs to play a local video file within rails.
I am using the video.js library
I have tried 2 different gems (github: seanbehan/videojs and
alexesDev/videojs)
I have tried in line javascript
I have tried precompiling the video as an asset by placing in
assets/video/test-meeting.m4v
config.serve_static_assets = true << is set in production.rb
*= require video-js << is set in application.css
//= require video-js << is set in application.js
When trying seanbehans gem:
in my view file I have tried the following
<%= videojs_rails sources: { mp4:
"file:///app/assets/video/test-meeting.m4v", webm:
"http://another.com/path/to/video.webm" }, width:"640", height:"400" %>
and
<%= videojs_rails sources: { mp4: "assets/video/test-meeting.m4v", webm:
"http://another.com/path/to/video.webm" }, width:"640", height:"400" %>
When I go to the page nothing renders, just a black box.
However when I use a link to a videofile on the web it works.
with alexesDev gem:
I installed the gem however the libraries are not showing.
when I use:
<%= video_player src: { mp4: '/assets/video/test-meeting.m4v' },
controls: true %>
I get "undefined method `video_player'"
when I use js in line with html and place the library in
assets/javascripts I get a blank black box as well.
Can anyone help?
I haven't tried either of those gems, but I have used VideoJS long-hand in both static HTML pages and Rails. It works pretty well, as long as all of the resources can be found and linked to one another.
I would start in baby steps here. First, put all the assets in the public folder, and hand-code a video tag on your page. Don't include VideoJS yet, simply see if you can get a video to display on your page. You may need to fiddle with different browsers and formats at this point -- Safari will play MPEG4 video, Chrome wants WebM, Firefox wants OGG or WebM. All of them will benefit from a JPEG poster frame.
There's nothing Rails is doing or not doing at this level that will change that. The video tag is designed to paper over these browser differences, and all that VideoJS does is provide a Flash fallback if someone visits with an elderly IE browser. But you have to start with a properly constructed video tag that plays in some browsers before you can layer on the VideoJS to clean up all differences.
<video id="video_player" controls width="720" height="240" poster="/poster.jpg">
<source src="/video.m4v" type="video/mp4"/>
<source src="/video.webm" type="video/webm"/>
</video>
Fiddle with this basic shell until you can see something on the screen (all that you will need to change are the actual paths to the sources). Once you have it working in some browsers, follow the instructions on the VideoJS documentation site to add the JavaScript and Flash assets to your server and reference them in your page.
Walter