在data中
vodPlayerJs: "https://player.polyv.net/script/player.js",
this.loadPlayerScript(this.loadPlayer);
if (this.player) {
this.onPause();//两个监听事件
this.onPlay();
}
我这里不知道到底是vid还是URL,所以两个的取值根据传送的参数决定的
loadPlayerScript(callback) {
if (!window.polyvPlayer) {
const myScript = document.createElement("script");
myScript.setAttribute("src", this.vodPlayerJs);
myScript.onload = callback;
document.body.appendChild(myScript);
} else {
callback();
}
},
// 暂停事件
onPause() {
let that=this;
this.player.on("s2j_onVideoPause", function (e) {
that.flag=true;
});
},
// 播放事件
onPlay() {
const _that = this;
this.player.on("s2j_onVideoPlay", function (e) {
_that.flag=false;
});
},
loadPlayer() {
const polyvPlayer = window.polyvPlayer;
this.player = polyvPlayer({
wrap: "#player" + this.index,
width: "100%",
height: "544",
vid: this.vid,
autoplay: false,
ban_preview_video: "on",
allowFullscreen:false,
url: this.url,
}