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

Posted on 2014-09-01
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 81

    Accepted Solution

    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

    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 method worked perfectly on iOS.

    Thanks for the help.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    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…
    The viewer will learn how to dynamically set the form action using jQuery.
    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)

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now