无法在jwplayer中为错误消息添加自定义消息

时间:2017-05-24 12:48:50

标签: jwplayer

这是我的代码。我想在JWplayer中显示自定义错误消息。目前我正在显示图像。如何在JWplayer中针对不同情况实现自定义错误消息。我想显示不同参数的错误消息。

var videoNode = document.getElementById("videoUrlPath").value;
    var player = jwplayer('play');
    var playerCall = true;
    var seeking = false;
    var currentPosition = 0;
    var jw_selector = "#play";
    player.setup({
        file: videoNode,
        width: "100%",
        aspectratio: "16:9",
        autostart: true,
        /*advertising: {
             client: 'vast',
             schedule: {
                 adbreak1: {
                     offset: "pre",
                     tag: '/static/assets/vast.xml',
                     'skipoffset': '5'
                      }
                     }
                  },
        "sharing": {
            "sites": ['facebook', 'twitter', 'email'],
            link: ''
        },*/
        skin: {
            name: 'myskin',
            url: 'assets/theme/js/jwplayer-7.8.6/skins/tfcskin.css'
        },
    });
    player.play();
    player.onSetupError(function (error) {
        player.setup({
            file: "http://content.jwplatform.com/videos/7RtXk3vl-52qL9xLP.mp4",
            width: "100%",
            aspectratio: "16:9",
            image: "assets/theme/images/error-video.jpg"
        });
        player.play();
    });
    player.onTime(function (callback) {
        currentPosition = callback.position;
        if (this.getPosition() === this.getDuration() && playerCall) {
            playerCall = false;
            document.getElementById("viewcountincrease").click();
        }
    })
    player.onPlay(function (event) {
        playerCall = true;
    })
    player.onSeek(function () {
        if (!seeking) {
            seeking = true;
            var _currentPosition = currentPosition;
            /* WITH A SMALL DELAY SCROLL BACK */
            window.setTimeout(function () {
                var elem = document.querySelector(jw_selector);
                jwplayer(elem).seek(_currentPosition);
            }, 100);
        } else seeking = false;
    });

1 个答案:

答案 0 :(得分:1)

如果您要显示自定义文本错误消息,则可以在播放器周围使用换行div。 onError和onSetupError事件返回错误消息,您可以在此页面找到错误消息列表:https://support.jwplayer.com/customer/portal/articles/1403682-common-error-messages

这是一个codepen示例: http://codepen.io/fdambrosio/pen/vmbPEK

HTML:

POST /bar

CSS:

<div id="wrapvideo">
    <div id='player'></div> 
</div>

JS:

#wrapvideo {
  width: 544px;
  height: 306px;
  display: inline-block;
  color: white;
  background-color: black;
}
#wrapvideo p {
    text-align: center;
}

对于每个不同的错误消息,您可以使用和图像或视频执行相同的操作