Link to home
Create AccountLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

jplayer

Hello,

Please look at the following. There is a folder sound with an mp3 file called memory.mp3. There is a folder called js with jquery.jplayer.min.js in it.

<html>
<head>
  <script type="text/javascript" src="/js/jquery.jplayer.min.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){
      $("#jquery_jplayer_1").jPlayer({
        ready: function() {
          $(this).jPlayer("setMedia", {
            mp3: "sound/memory.mp3"
          }).jPlayer("play");
          var click = document.ontouchstart === undefined ? 'click' : 'touchstart';
          var kickoff = function () {
            $("#jquery_jplayer_1").jPlayer("play");
            document.documentElement.removeEventListener(click, kickoff, true);
          };
          document.documentElement.addEventListener(click, kickoff, true);
        },
        loop: true,
        swfPath: "/js"
      });
    });
  </script>
</head>
<body>
  <div id="jquery_jplayer_1"></div>
</body>
</html>

This was a sample straight from jplayer.

Why no sound?
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Richard Korts

ASKER

That did it; thanks.

One question. How do we know that ajax.googleapis.com is going to be there "forever"?
Happy 4th of July!

The short answer is that we don't know for sure, but the very high likelihood is that it will be there longer than however long you'll need it to be there.

Longer answer:
The ajax.googleapis.com domain hosts popular Javascript frameworks for a multitude of websites including some corporation-sized sites, so if it ever goes down, it will cause some havoc on the internet. There are several of these types of hosts - Microsoft also hosts jQuery and jQuery UI and some other popular scripts for the public.

Part of the thought process here is that if your visitors have recently been on any other websites that ALSO link to that same jQuery URL, then their browsers will already have it in their cache, so there's no need to re-download it.

 Your site and every one else's site that uses it will load and perform faster and at the same time, Google and Microsoft and others like them are reducing the overall bandwidth usage on the internet. It's a pretty big effort with a lot of heft behind it.

There's no reason you can't download jQuery to your own site and host it if you want to, but you'll miss out on the benefits of the community caching and you'll be taking up more of your own bandwidth when Google's willing to take care of it for free.
FYI,

The jplayer version DOES NOT function correctly on the iPad.

But I guess you can't have everything.

Richard
Hi Richard,

I did some more research. Apparently, Apple decided to try to prevent automatic loading of remote audio files as a way to limit unintended bandwidth usage (e.g. user clicks on a site and they don't want to download 5 megs of audio automatically), so it works, but it requires user interaction to begin the play.

That said, it seems that someone figured out a way to fool mobile Safari into thinking the user clicked on a link to start the audio by creating a fake link that starts the audio, and then using Javascript to "click" the link for the user:

http://roblaplaca.com/blog/2010/04/14/ipad-and-iphone-html5-video-autoplay/