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">

jwplayer("myElement").setup({
playlist: [{
file: "jwplayer-7.2.2/MUNA.mp4",
image:"images.jpg",
titile: "My file",
displaytitle: true,
startparam: 'start',
//do{
//primary: "flash",
//label: "720p HD",
//stretching: "exactfit",
//controls: true,
//events:{
// 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

George

JW Player Support Agent  
0 rated :

You could use this:

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

// 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
setupPlayerWithCaptions();
}
else if (xhttp.readyState == 4 && xhttp.status == 404) {
// if it’s unsuccessful setup your alternate player
setupPlayerWithoutCaptions();
}
};

Sudhir Ranjan Rout

User  
0 rated :

var urlToFileVTT = "http://www.muna.com/caption/Muna.vtt";
function doesFileExistVTT()
{
var xhr = new XMLHttpRequest();
xhr.open('HEAD',urlToFileVTT,false);
xhr.send();

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

User  
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.

George

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

https://developer.jwplayer.com/jw-player/docs/developer-guide/customization/configuration-reference/#skin
http://stackoverflow.com/questions/707565/how-do-you-add-css-with-javascript

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

.jw-icon-cc{
display:none !important;
}

Sudhir Ranjan Rout

User  
0 rated :

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

George

JW Player Support Agent  
0 rated :

Hello Sudhir,

Here’s a test page:
http://qa.jwplayer.com.s3.amazonaws.com/~george/check_captions.html

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

Sudhir Ranjan Rout

User  
0 rated :

Hi,

Thnaks. My problem is resolved through ajax call.

This question has received the maximum number of answers.