如果JWPlayer中的主服务器失败,我该如何使用javascript自动切换到备用直播流? [英] How do I use javascript to automatically switch to a backup live stream if primary fails in JWPlayer?
问题描述
我正在尝试编写一个JavaScript函数,该函数将使JW Player的实例在发生错误(例如:主编码器出现故障)时自动从主实时HLS流切换到备用实时HLS流. /p>
我到目前为止所拥有的:
<div id="myElement">Loading the player...</div>
var playerInstance = jwplayer("myElement");
playerInstance.setup({
file: "http://server/primary/playlist.m3u8",
width: 640,
height: 360,
title: 'Basic Video Embed',
description: 'work damn you',
});
jwplayer('myElement').on('error', function(event) {
var prime = document.getElementById("myElement").innerHTML;
var backup = prime.replace("http://server/primary/playlist.m3u8", "http://server/backup/playlist.m3u8");
document.getElementById("myElement").innerHTML = backup;
});
在我的测试中,这不起作用(当主要停止时,该功能不执行,播放器旋转).我已经尝试过('错误'),('缓冲'),('空闲'),所有操作都具有相同的结果.
我将在此代码中进行哪些更改以实现自己的目标?欢迎任何帮助.
我们的一位工程师刚刚撰写了一篇有关此解决方案的精彩博客文章,其中包括代码示例: In my testing this doesn't work (when the primary stops, the function doesn't execute, the player just spins). I've tried ('error'), ('buffering'), ('idle'), all with the same results. What would I change in this code to accomplish my goal? Any help is welcome. One of our engineers just wrote a great blog post about this solution, including code samples: https://www.jwplayer.com/blog/building-insights-video-experience/ If there’s an error, the player switches to the error file. The video is a 10-second still that displays an informational slide. Once that completes, the player tries to play the previously determined currentStream. 这篇关于如果JWPlayer中的主服务器失败,我该如何使用javascript自动切换到备用直播流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!var playerInstance = jwplayer("myElement");
playerInstance.setup({
file: "http://server/primary/playlist.m3u8",
width: 640,
height: 360,
title: 'Basic Video Embed',
description: 'work damn you',
});
jwplayer('myElement').on('error', function(event) {
var prime = document.getElementById("myElement").innerHTML;
var backup = prime.replace("http://server/primary/playlist.m3u8", "http://server/backup/playlist.m3u8");
document.getElementById("myElement").innerHTML = backup;
});
insightsPlayer.on('error', function(event) {
playStream('error');
});
insightsPlayer.on('complete', function(event) {
playStream(currentStream);
});