[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2014-09-01
Medium Priority
Last Modified: 2014-09-03
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">
          file: "test.mp4",          
          width: "100%",
          aspectratio: "12:5",
	  autostart: "false"
<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() {

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.
Question by:kevinvw1
LVL 83

Accepted Solution

leakim971 earned 2000 total points
ID: 40299786
Your issue is you made you ajax call asynchronous, you need a synchronous ajax call to make it work

imagine an ajax call like a timer like this one :

setTimeout(fncBuildVideo, 300000); // callback function called after 300s

now you click, but the video will start in 300s
I think it's clear now the video should not start because it break the user action

but there's no logic difference between 3ms and 300s

so make your ajax call synchronous,

$.ajax({ async:false,

Author Comment

ID: 40302168
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.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question