Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JW-Player and Rails 3.2

I'm trying to use JW-Player in my application. Researching the issue a bit, there seems to be several abandoned efforts to produce a gem, and the latest is undocumented. So, here's how I'm going about it:

I downloaded the JW-Player version 6, unzipped and copied the files in my /app/assets/javascripts directory as follows:

app/assets/javascripts/jwplayer/jwplayer.js
app/assets/javascripts/jwplayer.html5.js
app/assets/javascripts/jwplayer.flash.swf

In my app/views/layouts/application.html.erb, I have the following:

<head>
    <%= javascript_include_tag "/assets/javascripts/jwplayer/" %>
</head>

and in app/views/pages/about.html.erb, I have the following:

<%= jw_player("http://xxxxx/video.mp4",
            :width => 200, :height => 110) %>

Here's what happens when I click on the About page link:

Showing xxxxxxxx/app/views/pages/about.html.erb where line #10 raised:

undefined method `jw_player' for #<#<Class:0x007fe77e37c018>:0x007fe780c1f678>

First time user of JW-Player.

like image 577
EastsideDev Avatar asked Dec 06 '25 04:12

EastsideDev


1 Answers

When implementing JWPlayer 6.6, we stood before the choice of putting the jwplayer.flash.swf file into the public folder, to make the flash mode work, but it seemed very messy to have the files separated like that. What I did in the end to make it work both on development and production was:

  • Put all 3 files to vendor/assets/javascripts/jwplayer
  • Rename jwplayer.js to jwplayer.js.erb
  • Inside jwplayer.js.erb, update the flash file path config like this (the 1st line with the html5 file path config is just for reference)

    j={type:"html5",src:e.base+"jwplayer.html5.js"},
    b={type:"flash",src:"<%= asset_path('jwplayer/jwplayer.flash.swf') %>"};
    

    (note that the "e.base+" before the path was removed for the flash file path - that's the trick that allowed working relative paths in the development environemtn)

In my understanding, the JWPlayer license allows modifications like this: "Adaptations Publisher shall be permitted to make Adaptations reasonably necessary for the purpose of exercising its rights under these Terms of Service, such as Adaptations to integrate the Products into Publisher’s websites or other properties. All Adaptations created by Publisher are strictly for its own Use and Publisher is prohibited from Distributing any Adaptation it creates. The Company reserves the right to prohibit the Use of any Adaptation in its sole discretion."

like image 196
obiuquido144 Avatar answered Dec 07 '25 18:12

obiuquido144



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!