jwplayer: seek function doesn't work on mobile safari?
Asked Answered
N

0

7

Test page (not working properly on iPhones)

I have hundreds of videos on my site, and I want to replace their openings. To avoid re-render all the videos again, I use the following code to add the new opening as a playlist item that is going to play before the original video, and then when the original video is being played, the first 20 seconds (where the old opening is) will be cut.

<html>
<head>
  <script src="/templates/it_365news/js/jwplayer/jwplayer.js" type="text/javascript"></script>
  <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
  <script>
    $(document).ready(function(){
      $('#ready').html('document is ready at ' + new Date().getMinutes() + ":" + new Date().getSeconds() + ":" + new Date().getMilliseconds())
    })
  </script>
</head>
<body>
  <div id="vp0">

  </div>
  <div id="ready" style="background:yellow">

  </div>
  <div id="vr" style="background:red">

  </div>

  <div id="vl" style="background:blue">

  </div>
  <script>
    jwplayer.key = 'bwIDfauoN3m+MClNdkQb0YamUxTfzWw7ygugtA==';
    jwplayer('vp0').setup({
      "file": "http://video.jiuan.org/2017/May/luntan.mp4",
      "image": "http://www.jiuan.org/ffmpeg_image.php?file=2017/May/luntan.mp4&time=00:00:03&browser=true",
      "width": "100%",
      "aspectratio": "16:9"
    })
  </script>
  <script>
    var jw = jwplayer('vp0');
    var file = jw.getPlaylistItem('0').file;
    var image = "http://www.jiuan.org/ffmpeg_image.php?file=2017/May/UNG1.mp4&time=00:00:09&browser=true";
    var title = jw.getPlaylistItem('0').title;
    var openning = {"file": "/videos/UNG.mp4","image": image,"title":title};
    var video = {"file":file};
    jw.setup({
      "playlist":[openning,video],
      "visualplaylist": "false",
      "width": "100%",
      "aspectratio": "16:9"
    })
      .on('playlistItem',function(){
        $('#vr').html('video is ready at ' + new Date().getMinutes() + ":" + new Date().getSeconds() + ":" + new Date().getMilliseconds());
        if (this.getPlaylistIndex() === 1){
          $('#vl').html("cut");
          this.seek(20);
          $('#vl').append('done');
        }
      });
  </script>
</body>
</html>

This works out on window PC, Mac book air and Android phones, but when it comes to iPhone, the new opening is successfully added, but the old opening is still being played, a.k.a the this.seek(20) seems not working. Is there a better way to debug? And is there any other way to achieve my goal?

Nevsa answered 27/5, 2017 at 17:7 Comment(5)
This help page says that "Auto-starting a video on page load is not possible on mobile.". Hence this could be why seek in on('playlistItem') is not working.Emmyemmye
I know this has got to do with the difference between mobile and desktop, but this one seems irrelevant. In my case, there is no problem with auto playing 2nd item in the list after the 1st item is finishedNevsa
Ok, just thought I'd highlight that page just in case you hadn't seen it. Issues like this i.e. browser specific are a real pain. Are you getting any browser console errors when run on an iPhone?Emmyemmye
What I thought was a solution proved to be wrong. On this page:developer.jwplayer.com/jw-player/demos/basic/… seek() is working on mobile safari. I really don't understand what is wrong with my code and why the seek() function here is not working. Could it be because its a playlist?Nevsa
Have you tried "jw.seek(20);" instead of "this.seek(20);". Perhaps "this" is referring to the playlist item instead of the jwplayer? I'm just thinking out loud, as I haven't debugged the code. Wouldn't explain why it works on other browsers though!Emmyemmye

© 2022 - 2024 — McMap. All rights reserved.