问题描述
由于环境原因,我必须将代码实现到其中,因此无法使用“导入”。我可以得到我需要的库,但是尝试使用它时遇到以下错误。
“ jQuery.Deferred异常:未定义videojs ReferenceError:未定义videojs”
我找到了videoJS的变通办法,该变通办法要求使用类似以下的内容
import videojs from 'video.js';
window.videojs = videojs;
require('videojs-http-source-selector');
不幸的是,由于导入是不可能的,所以这是行不通的。有办法解决这个问题吗?
以下是我所讨论的代码。我在解决方案中使用ScriptLoader按文件路径加载库。
/*This JS is meant to create an HMTL video component,then stream JSVideo/HLS to it. It's integrated in a no-code/low-code solution and is very particular about structure.*/
function MyControl() { };
MyControl.prototype.initialize = function(host,component){
/*Here we load our libraries. We must load it this way because of the way we integrate javascript into the no code solution*/
$.when(
$DP.ScriptLoader.LoadScript(
virtualPath + "/scripts/FormControls/jsFiles/video.js"
)
)
// Here we assign 'host' to a variable on this control,// so that we can access it later:
this.host = host;
// Create and configure the video elemnt:
var video = document.createElement('video-js');
video.setAttribute("id","videoplayer");
video.setAttribute("class","video-js vjs-default-skin");
// Add the video to the 'host' jquery object:
host.append(video);
//Gets the source and plays on our video element previosuly made.
const player = videojs('videoplayer',{
html5: {
hls: {
withCredentials: true
}
},controls : true,fluid: true,controlBar: {
children: ['playToggle','volumePanel','currentTimedisplay','timeDivider','durationdisplay','progressControl','livedisplay','seekToLive','remainingTimedisplay','customControlSpacer','playbackRateMenuButton','chaptersButton','descriptionsButton','subsCapsButton','audioTrackButton','settingMenuButton','qualitySelector','fullscreenToggle']
},preload : 'auto',poster : '',});
player.src({
src: 'http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8',type: 'application/x-mpegURL'
});
player.play();
};
MyControl.prototype.resize = function(height,width) {
if (this.host && height && width && (height > 0) && (width > 0)) {
this.host.css({ width: width,height: height });
}
};
MyControl.prototype.setValue = function(data){
// This control has no inputs,so no code is necessary here.
};
MyControl.prototype.getValue = function() {
// Output data should be an object with properties that match the
return {
};
};
解决方法
怎么样
var videojs = require(/path/+'video.js');