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

Keep Trying Until HLS Stream Starts - Was Working in JW6, can't seem to get it going in JW7


I have a self-hosted player for live events that are broascast in HLS .M3U8 format. I want the player to autostart. The issue is that if the stream hasn't started yet, then it just returns an error message and stops. In JW Player 6 I worked around this by intercepting the error and then telling the player to wait a few seconds and try again. Sadly this trick doesn't work in JW Player 7. Once an error is reached the player seems to ignore other commands.

Here is the code I have that was working fine on JW Player 6.

jwplayer().onError( function(event){
if (event.message == 'Cannot load M3U8: No levels in manifest' || event.message == 'Cannot load M3U8: 404 not found'){
setTimeout(function(){ jwplayer().play(true); }, 3000);
}
})

Is there a way to make this work in JW7? Is there a better method I should be using?

Thanks in advance.

9 Community Answers

Alex

JW Player Support Agent  
0 rated :

Hi, there.

The syntax in JW 7’s JavaScript API is slightly different than that of JW 6. Instead of jwplayer().onError(), you would use jwplayer().on(“error”). So, for example, the code that you included in your post should look like this:

jwplayer().on("error", function(event) {
  if (event.message == 'Cannot load M3U8: No levels in manifest' || event.message == 'Cannot load M3U8: 404 not found') {
    setTimeout(function(){ jwplayer().play(true); }, 3000);
  }
});

I would also recommend, for testing purposes, you include some sort of output to the console to see if your function is actually firing. Then, if the console logs the output but your function is still not working, you know there may be some issue with the logic of your conditional or elsewhere inside the main function.

I hope that helps! Please let us know.

Thanks.

test867

User  
0 rated :

I tried your updated code and the issue is still occurring.

Here is the new code I am now using:
jwplayer().on('error', function(event) {
if (event.message == 'Cannot load M3U8: No levels in manifest' || event.message == 'Cannot load M3U8: 404 not found') {
console.log('Error Message Occurred');
setTimeout(function(){ jwplayer().play(true); }, 3000);
}
});


I am getting the message in my console, but the player never tries to play again.

Alex

JW Player Support Agent  
0 rated :

Can you give me the URL of the HLS stream you are testing this against? I’d like to take a look at a couple of things.

Thanks.

test867

User  
0 rated :

Here is the m3u8 file URL:

http://live-mobile.cdn01.net/hls-live/202E1F/default/dvr/stream_11484_1.m3u8


As I said, this worked fine on JW6.

Alex

JW Player Support Agent  
0 rated :

Hi, there.

It looks like we were missing one step. Apparently, we need to call jwplayer().stop(); to unload the file from the player before we call jwplayer().play(); to retry it. You can see this in action, including an example of the code I used at http://qa.jwplayer.com/~abussey/demos/64379-retry-hls.html.

Please let me know if you need any more help or have any other questions.

Thank you!

test867 N/A

User  
0 rated :

Thank you, that fixed it.

Alex

JW Player Support Agent  
0 rated :

Not a problem.

test867

User  
0 rated :

I upgraded to 7.2.2 and the problem has returned. I am using the code you listed in the demo, but it isn't working anymore.

Can you see what it would take to get this working again with 7.2.2?

Pat

User  
0 rated :

I'm also having this problem in 7.2.4

This question has received the maximum number of answers.