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

Problem to add multiple sources


Hello,

I am trying to add multiple sources to my website,
Basically, I want JW player will load 1st link first (link1), if 1st link's broken then load second link (link2).

Here is my example :

http://canthotv.vn/huy/jwplayer/?l=http://media.canthotv.vn/2015/TH/07/20/PS_themanhvocotruyen.mp4&i=http://canthotv.vn/wp-content/uploads/2015/07/vocotruyen.jpeg&w=390&h=300&a=1&l2=http://media.canthotv.vn/2015/TH/07/20/Bantincuoingay_19072015.mp4

My problem is JW Player doesn't work as I thought, when I changed .mp4 (link1) to .mp4abcdef, it's working, however when I change link1 path, it doesn't working.

Here is the code in index.php

<?php
$allowurl=$_SERVER['HTTP_HOST'];
//if(!strstr($_SERVER['HTTP_REFERER'],$allowurl)) exit("");
$l=$_GET['l'];
$l2=$_GET['l2'];
$w=$_GET['w'];
$h=$_GET['h'];
$i=$_GET['i'];
$a=$_GET['a'];
if($a==1) $a="true"; else $a=false;
?>
<!DOCTYPE html>
<html>
<style type="text/css">
*{padding:0; margin:0;}
</style>
<body>
<div id="mediaplayer">Loading...</div>
<script type="text/javascript" src="jwplayer.js"></script>
--License Key--
<script type="text/javascript">
jwplayer("mediaplayer").setup({
sources: [
{file: "<?php echo $l; ?>"}
<?php if($l2!="") echo ",{file: \"".$l2."\"}"; ?>
],
image: "<?php echo $i; ?>",
sharing: {},
skin: "/jwplayerskins/five.xml",
autostart: "true",
screencolor: "ffffff",
width: "<?php echo $w; ?>",
height: "<?php echo $h; ?>",
stretching: "uniform",

});
</script>
</body>
</html>

thank you

2 Community Answers

jherrieven

User  
1 rated :

Setup 1:
======

sources:[
{file: a.mp4abcdef},
{file: b.mp4},
]

Because the "mp4abcdef" and "mp4" are considered to be different video types (based on the extension) JW Player will perform a fallback routine checking which it is able to play based on the browsers supported/playable media types. This is why this appears to work - as the "mp4abcdef" is ignored.

Setup 2:
======

sources:[
{file: a.mp4},
{file: b.mp4},
]

Here they are both considered "mp4" and so JW Player will assume they are simply different quality versions of the same media - which means if the first one is not actually available (due to a path error), then that whole media item is considered invalid.

In order to achieve what you want, the best option would be to initially setup using a single source and then detect a media error using the "onError" event. You can then cycle through alternative files by repeating the setup, as demonstrated by this example:


(function(){
var fileOptions = [
"http://media.canthotv.vn/2016/TH/07/20/PS_themanhvocotruyen.mp4",
"http://media.canthotv.vn/2016/TH/07/20/Bantincuoingay_19072015.mp4",
"http://media.canthotv.vn/2015/TH/07/20/Bantincuoingay_19072015.mp4"
];
var fileSource = 0;

function buildPlayer(){
if(fileSource<fileOptions.length){
jwplayer("mediaplayer").setup({
file: fileOptions[fileSource],
image: "http://canthotv.vn/wp-content/uploads/2015/07/vocotruyen.jpeg",
sharing: {},
skin: "/jwplayerskins/five.xml",
autostart: "true",
screencolor: "ffffff",
width: "390",
height: "300",
stretching: "uniform",
abouttext: "Copyright Canthotv.vn",
aboutlink: "http://canthotv.vn",
});
jwplayer("mediaplayer").onError(function(){
jwplayer("mediaplayer").stop();
fileSource++;
buildPlayer();
});
} else {
jwplayer("mediaplayer").remove();
}

}
buildPlayer();
})();

James Herrieven

thehuythtpct

User  
0 rated :

Thank you very much James Herrieven

The Huy

This question has received the maximum number of answers.