JPlayer + Rails 3.1.3 swfPath?


I am trying to get jPlayer to work with flash backup in rails application and so far no luck! Now my constructor looks like this:

$("#jquery_jplayer_1").jPlayer({
preload: "auto",
errorAlerts: true,
swfPath: "javascripts",
solution: "flash, html",
supplied: "oga",
wmode: "window",
ended: function(e) {
        ...some function...
}
});

I can't get swfPath correctly, and I must have something missing here about how jPlayer is looking for this path. My other assets, such as images from style sheets, seem to be correctly redirected to the folder with folders / folders of assets. I can't seem to find a magic combination to get jPlayer to find Jplayer.swf. I tried to put the swf file in the shared folder, in the folder in the shared folder, in the resources folder and in the javascripts folder in the resources folder. Bad luck! Has anyone considered this issue before?

+3
source share
3 answers

... , :)

(Rails 3.2):

$(document).ready(function(){
   $("#jplayer").jPlayer({
       ready: function (event) {
           $(this).jPlayer("setMedia", {
               m4a: "url goes here"
           });
       },
       swfPath: "/",
       supplied: "m4a",
       solution: "flash, html"
   });
});

coffeescript:

$ = jQuery
$ ->
  $(document).ready ->
    $("#jplayer").jPlayer(
      ready: (event) ->
        $(this).jPlayer "setMedia",
          m4a: "url goes here"
      preload: "auto",
      swfPath: "/",
      solution: "html, flash",
      supplied: 'm4a')

Jplayer.swf public/. !

+2

, - swf .

,

config.assets.paths << Rails.root.join("app", "assets", "swf")

config/application.rb Jplayer.swf vendor/swf/Jplayer.swf

JS .js.erb

$(document).ready(function(){
  $("#jplayer").jPlayer({
    swfPath: "<%= asset_path "Jplayer.swf" %>"
  });
});
+1

Since no one has mentioned this here yet, you can also do this in jplayer initialization code:

Works with Rails> = 3.2, which uses an asset pipeline!

swfPath: "<%= escape_javascript(asset_path('jplayer/Jplayer.swf')) %>",
solution: "flash,html",
supplied: "rtmpa,mp3",

And remember that the file has capital J :-)

0
source

All Articles