Link to home
Start Free TrialLog in
Avatar of kevinvw1
kevinvw1

asked on

JWPlayer - start video on mobile device with real button press.

I have an issue where JWPlayer (javascript video player) won't start playing a video if the play method is called from a callback function.
(NOTE:  I am NOT trying to auto start the video on page load.  Everything I am doing is from a user-initiated button press.)
Also, this works correctly on desktop (surprise, surprise).

I have a simple page with a JWPlayer object (excerpt) -

<div id="jw" class="container">
<div id="jw1">Loading the player...</div>
	<script type="text/javascript">
	jwplayer("jw1").setup({
          file: "test.mp4",          
          width: "100%",
          aspectratio: "12:5",
	  autostart: "false"
	});		
	
	</script>				
</div>
<input id="btn1" type="button" value="Another Play Button" onclick="fncBuildVideo2();"/>

Open in new window

The player loads correctly and if you push the play button on the player window the video starts fine.
I added a button called "Another Play Button" and it calls "fncBuildVideo()"
When fncBuildVideo() looks like this, the video starts playing when you push the button -

function fncBuildVideo() {
	jwplayer("jw1").play();
}

Open in new window


But before I call jwplayer("jw1").play() I need to first make an ajax call to do some server side stuff.
So I placed jwplayer("jw1").play() in the callback function and now the video will not start playing.
This is all initiated from a button click so I am not trying to circumvent the mobile device auto start limits.
But it appears that the mobile device thinks I am trying to circumvent and it refuses to start the video when the play method is called from the callback function.

Any thoughts on how I can do this?

Thanks, Kevin.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kevinvw1
kevinvw1

ASKER

Thanks the async setting was part of the problem.
It solved the above example perfectly.

But my next step was to dynamically load a different video (based on the ajax call).
I was trying to call the jwplayer().setup method after the button click instead of on page load.
It worked fine on desktop but not on iOS.
In order to get it to work properly I had to keep the jwplayer.setup() method on the page.
Then after I clicked the button and made the ajax call (to get the name of the next video file),
I had to do this - jwplayer().load([{file:" + newVideoToPlay }]);
Then the jwplayer.play() method worked perfectly on iOS.

Thanks for the help.

Kevin.