VideoJS 分辨率切换器报告 "this.updateSrc is not a function"

VideoJS Resolution Switcher reports "this.updateSrc is not a function"

我随机遇到这个错误。有时视频加载正常,但大部分显示 "updateSrc is not a function"。视频通常在页面刷新时加载。我已经尝试了所有方法,但无法解决这个问题。

HTML

<video id="<?php echo $id; ?>" class="video-js vjs-16-9 vjs-big-play-centered" controls preload="auto" width="100%" height="100%" poster="<?php echo (isset($mPoster))?$mPoster:'';?>" data-setup="{}">
                        <p class="vjs-no-js">
                            To view this video please enable JavaScript, and consider upgrading to a web browser that
                            <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
                        </p>
                    </video>

JavaScript

var videoplayer = videojs('<?php echo $id; ?>', {
            plugins: {
                videoJsResolutionSwitcher: {
                    default: 480,
                    dynamicLabel: true
                }
            }
        }, function() {
            this.updateSrc(<?php echo (isset($code))?$code:'';?>)
            this.preload(false)
            this.on('resolutionchange', function() {
                console.info('Source changed to %s', this.src())
            })
            this.autoplay(true)
        });

错误

通过动态生成视频标签找到了解决方法。 这是代码:

 var videotaghtml= "<video id='<?php echo $id; ?>' class='video-js vjs-16-9 vjs-big-play-centered'"+ " controls preload='auto' width='100%' height='100%' poster='<?php echo (isset($mPoster))?$mPoster:'';?>'"+ "data-setup=\"{}\">"+
        "<p class=\"vjs-no-js\">"+
        "To view this video please enable JavaScript, and consider upgrading to a web browser that"+
        "<a href=\"http://videojs.com/html5-video-support/\" target=\"_blank\">supports HTML5 video</a>"+
        "</p>"+
        +"</video>";

 $( "#videotag" ).append(videotaghtml);

我以前遇到过这个问题。

我相信这是因为您的代码中有 data-setup={}。因此,javascript 中的插件未初始化,因为 videojs 仅考虑数据设置或插件。

有时它会考虑 data-setup={}。因此,不调用包含 updateSrc 方法的 videojs 分辨率切换器。因此错误。只需删除 data-setup={} 就可以了。