Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Caption File Existance

will this be possible to check if caption file exist or not in server by calling ajax call to the file.

if file returns successfully then show the cc button and play the caption file and if file returns 404 error then hide the caption button from the player.

here is my code but i don't know how to create a ajax request for this.

<script type ="text/javascript">

playlist: [{
file: "jwplayer-7.2.2/MUNA.mp4",
titile: "My file",
displaytitle: true,
startparam: 'start',
//primary: "flash",
//label: "720p HD",
//stretching: "exactfit",
//controls: true,
// onPlay: function(event) {
// alert('Playing!');
// }
// },
tracks: [{
file: "jwplayer-7.2.2/MUNAA.vtt",

label: "English",
kind: "captions",
"default": false



captions: {
color: '#FF33F9',
fontSize: 24,
backgroundOpacity: 20


jwplayer().on('volume', function(e) {
alert("Volume is changed to: "+ e.volume);
jwplayer("myElement").on('captionsChange', function(e1) {
alert("play-during: "+ e1.getCaptionsList());

7 Community Answers


JW Player Support Agent  
0 rated :

You could use this:

var xhttp = new XMLHttpRequest();
// Request your live stream URL“GET”, “YOUR_CAPTIONS”, true);

// When the xhttp request gets a status OK parse the XML
xhttp.onreadystatechange = function() {

if (xhttp.readyState == 4 && xhttp.status == 200) {
// if it’s successful setup your player
else if (xhttp.readyState == 4 && xhttp.status == 404) {
// if it’s unsuccessful setup your alternate player

Sudhir Ranjan Rout

0 rated :

var urlToFileVTT = "";
function doesFileExistVTT()
var xhr = new XMLHttpRequest();'HEAD',urlToFileVTT,false);

if (xhr.status == "404") {

alert("File is not found");
console.log("File doesn't exist");
return false;
// $("captions").hide();

i want to on successful file return show the cc button & on failure hide the cc button.

i am able to know the existance of file based on my request but not able to hide or show the cc button.

so please help me on this

} else {

alert("File is");
console.log("File exists");
return true;
// $("captions").show();

Sudhir Ranjan Rout

0 rated :

Hi George,

This is not my question.My question is to hide the CC button if caption file does not exist and display the cc button if caption file exist.

i am able to check the existance of file but don't able to hide the cc button.


JW Player Support Agent  
0 rated :

You’ll want to either setup the player with a different skin or add a CSS declaration to the stylesheet

in both cases you’ll want to add something like this:

display:none !important;

Sudhir Ranjan Rout

0 rated :

Hi George can u add this line to my existing code so that i will be able to trace my problem.


JW Player Support Agent  
0 rated :

Hello Sudhir,

Here’s a test page:

Please keep in mind that we don’t write custom code implementations, any further debugging will be up to your team.

Sudhir Ranjan Rout

0 rated :


Thnaks. My problem is resolved through ajax call.

This question has received the maximum number of answers.