Question

I have a jw player where the link click changes the video. I also have other type of players so I need to hide jw player and switch to youtube player. The problem is that the jw player loads the video on second click afte the video player is visible. Any solution so that the player loads the video on first click.

<div id="jw_container">       
<script type="text/javascript" src="https://content.jwplatform.com/players/hsdfQtN-ieOuTCiv.js"></script>
</div>

<li><a href="javascript:playTrailer('Bmodfg5AS')" id="vid_link3">video</a></li>

function playTrailer(key) {
    $('#jw_container').show(); // show video player        
    jwplayer().load("https://content.bitsontherun.com/jw6/" + key + ".xml");
    jwplayer().play({
        autostart: false
    });
}

as you can see, first click make the video visible and second load the specific video. There is one solution to this and instead of using show(); to use .css('visibility','visible') but that causes some css issues.

The actual code:

var loaded = false;
    function playTrailer(key) {   
      $('#yt_container').hide();    // hide youtube  
      $('#jw_container').show("slow", function() {    
        jwplayer().load("https://content.bitsontherun.com/jw6/" + key + ".xml");        
        });
        loaded = true;
    }
    jwplayer().onPlaylistItem(function() {
      if(loaded) {    
        jwplayer().play({autostart:false});
      }
    })
Was it helpful?

Solution

I think what you need is to set

EDIT

 $('#jw_container').show(0,'', function() {
    // Animation complete.
jwplayer().load("https://content.bitsontherun.com/jw6/" + key + ".xml");
jwplayer().play(true);
  });

Hypothetically it might be that the playlist is not loaded so the play method is being executed on nothing. So this might also work:

function playTrailer(key) {
     $('#jw_container').show(); // show video player        
        jwplayer().load("https://content.bitsontherun.com/jw6/" + key + ".xml");
    jwplayer().onPlaylist( function(event){
        jwplayer().play(true);
      });
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top