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

Unexpected error


Hello,

I'm struggling with some authorisation code to protect my live streams.
I have a flussonic stream server with token authentication.
All is fine when i use the <iframe> option but that player isn't my first choice,i just want to use jwplayer.

I have follwing code from the stream server with auth token...


<?php
$streamname = "Stream-7";
$flussonic = "https://xxxx.xxx.sc";
$password = "5678";
$session_lifetime = 3; // in hours

$query = http_build_query(array(
"password" => $password,
"name" => $streamname,
"ip" => $_SERVER["REMOTE_ADDR"],
"salt" => bin2hex(openssl_random_pseudo_bytes(16)),
"starttime" => time(),
"endtime" => time() + $session_lifetime*3600));

$token = file_get_contents("$flussonic/securetoken/sign?$query");
$embed = "$flussonic/$streamname/index.m3u8?token=$token";
?>


And the html i use is...


<body>
<div id="player">Loading the player...</div>
<script>
// Setup the player
const player = jwplayer('player').setup({
file: '<?= $embed?>'
});

// Listen to an event
player.on('pause', (event) => {
alert('Why did my user pause their video instead of watching it?');
});

// Call the API
const bumpIt = () => {
const vol = player.getVolume();
player.setVolume(vol + 10);
}
bumpIt();
</script>
</body>


When i do it this way i get error Uncaught SyntaxError: Invalid or unexpected token
<a href="https://gyazo.com/4db1a7d87ebb3dcd15440e62d95ba9b3"><img src="https://i.gyazo.com/4db1a7d87ebb3dcd15440e62d95ba9b3.png" alt="https://gyazo.com/4db1a7d87ebb3dcd15440e62d95ba9b3" width="1554"/></a>



When i use the player without the token scrip the player runs perfect!!


<body>
<div id="player">Loading the player...</div>
<script>
// Setup the player
const player = jwplayer('player').setup({
file: 'https://xxxx.xxx.sc/Stream-7/index.m3u8'
});

// Listen to an event
player.on('pause', (event) => {
alert('Why did my user pause their video instead of watching it?');
});

// Call the API
const bumpIt = () => {
const vol = player.getVolume();
player.setVolume(vol + 10);
}
bumpIt();
</script>
</body>

When i use the standard iframe embed option from the streamserver i have excactly the same streamurl with the token

<a href="https://gyazo.com/c7e28c3ee13b831c2619132a5999c0d1"><img src="https://i.gyazo.com/c7e28c3ee13b831c2619132a5999c0d1.png" alt="https://gyazo.com/c7e28c3ee13b831c2619132a5999c0d1" width="1080"/></a>


Does anyone know what the problem here is i searching already a week to find the solution!!

Thanks in advance

10 Community Answers

Todd

JW Player Support Agent  
0 rated :

Do your tokenized HLS URLs play in our Stream Tester at https://developer.jwplayer.com/tools/stream-tester/ ?

And why are you setting jwplayer.key on top of the cloud-hosted player? We already assign a rotating key in this player.

b...

User  
0 rated :

Hey;

I tested with several players and most of them give me same error.
It seems the https url is the problem and i do not why!!
With the https url some players wont load at all and give me blank page, but when i make it an http url the player load but it give me
http error because cant load http over https

Player with https:
https://www.fhe.sc/jw.php

Player without https
https://www.fhe.sc/jwnos.php

There is 1 player that load with this configuration, its all weird

Todd

JW Player Support Agent  
0 rated :

Your HTTPS page is missing a comma after the aspect ratio line. And make sure you remove any extra line breaks inside the file line.

I would also suggest that you change the div ID to something that does not start with a number, as this can cause CSS issues.

Hope this helps,
Todd

b...

User  
0 rated :

Hello Todd,

That didn't work,and it's driving me crazy :-)
With S IN https ( IN php script) the whole player doesn't load :-) and give unexpected token error
https://www.fhe.sc/withs.php

When i remove the S from https ( IN php script) the player will load,but give me because i cannot run http over https
and we get the wrong path to the token script...... but the token error is gone :-)
https://www.fhe.sc/with-s.php

Weird huh

Todd

JW Player Support Agent  
0 rated :

I do not see any JW code or setup() call at https://www.fhe.sc/withs.php

For https://www.fhe.sc/with-s.php, I see a line break at the end of the file URL before the closing " that should be removed

b...

User  
0 rated :

sorry have the wrong urls in above posts
i shoud be

with S https://www.fhe.sc/with-s.php
without S https://www.fhe.sc/without-s.php

b...

User  
0 rated :

It doesn't matter this linebreak,i have other player running with same line break https://www.fhe.sc/hola.php

I dont see in script where i can manage it so there will be no line break

<?php
$streamname = "7";
$flussonic = "http://sports.fhe.sc";
$password = "efgh";
$session_lifetime = 3; // in hours

$query = http_build_query(array(
"password" => $password,
"name" => $streamname,
"ip" => $_SERVER["REMOTE_ADDR"],
"salt" => bin2hex(openssl_random_pseudo_bytes(16)),
"starttime" => time(),
"endtime" => time() + $session_lifetime*3600));

$token = file_get_contents("$flussonic/securetoken/sign?$query");
$embed = "$flussonic/$streamname/index.m3u8?token=$token";
?>

<!DOCTYPE html>
<!-- JW Player Library -->
<script src="https://content.jwplatform.com/libraries/PAgH0r1Z.js"></script>
<script>jwplayer.key='PV4c2OMNQ89pkHF6L2cODHP9';</script>
<!-- div for the player -->
<div id='streamone'></div>

<!-- Script to display video file in the player div -->
<script type='text/javascript'>
jwplayer('streamone').setup({
// URL to the video file
file: "<?= $embed?>",
width: '100%',
aspectratio: '16:9',
type: 'hls',
});
</script>

I hope it can be fixed ,so i can buy a licence for jwplayer.

b...

User  
0 rated :

Case closed :-)
It is working now, but the strangest thing is it's working with other player with the linebreak, but it was not working with the linebreak in jwplayer.
Searched alot in streamserver php files and found that the linebreak was the issue.

hashstr = to_s(qs.name) .. to_s(ip) .. to_s(qs.starttime) .. to_s(qs.endtime) .. to_s(secure_token) .. to_s(qs.salt)

hash = crypto.sha1(hashstr) .. "-" .. to_s(qs.salt) .. "-" .. to_s(qs.endtime) .. "-" .. to_s(qs.starttime)
return "http", 200, {}, hash.."\n"
end


I deleted the \n and player is loading.

Thanks for all help ethan,i was never expecting the line break because it was runnning on other player :-)

b...

User  
0 rated :

opps sorry wrong name, thanks todd

Todd

JW Player Support Agent  
0 rated :

Glad I could help! And I am glad it is working now!

This question has received the maximum number of answers.