<view class="video-js vjs-big-play-centered " ref="video" style="width: 100vw;height: 100vh;"></view>
createVideo() {
var video = document.createElement('video')
video.id = 'video';
video.setAttribute("playsinline", "true");
video.setAttribute("webkit-playsinline", "true");
video.setAttribute("x5-video-player-type", "h5-page");
// video.setAttribute("width",this.winWidth);
// video.setAttribute("height",this.winHeight);
video.setAttribute("style", `object-fit:fill;width:${this.winWidth};height:${this.winHeight};background-color:#111111`);
video.controls = false;
video.autoplay = true;
video.preload = "auto";
video.playsinline = false; //解决在iPhone中播放时自动全屏问题
var source = document.createElement('source')
source.src = this.url;
source.type = "application/x-mpegURL"
video.appendChild(source)
this.$refs.video.$el.appendChild(video)
let that = this;
let player = videojs('video', {
autoplay: 'play',
preload: 'auto'
}, function onPlayerReady() {
//
// videojs.players.video.player_.play()
console.log(videojs.players.video.player);
// this.play();
this.on("loadstart", () => {
console.log("开始请求数据 ");
videojs.log('正在加载中...!');
})
this.on("progress", function() {
console.log("正在请求数据 ");
})
this.on("loadedmetadata", function() {
console.log("获取资源长度完成 ")
})
this.on("canplaythrough", function() {
console.log("视频源数据加载完成")
})
this.on("waiting", function() {
console.log("等待数据")
});
this.on("play", function() {
that.hidePlayBtn = true;
console.log("视频开始播放")
});
this.on("playing", function() {
uni.hideLoading();
console.log("视频播放中")
});
this.on("pause", function() {
uni.hideLoading();
console.log("视频暂停播放")
that.hidePlayBtn = false;
});
this.on("ended", function() {
console.log("视频播放结束");
});
this.on("error", function() {
uni.hideLoading();
console.log("加载错误")
this.errorDisplay.close(); //将错误信息不显示
// 提示信息,并放出播放按钮
that.$mptoast('直播还未开始',2);
this.pause();
});
this.on("seeking", function() {
console.log("视频跳转中");
})
this.on("seeked", function() {
console.log("视频跳转结束");
})
this.on("ratechange", function() {
console.log("播放速率改变")
});
this.on("timeupdate", function() {
console.log("播放时长改变");
})
this.on("volumechange", function() {
console.log("音量改变");
})
this.on("stalled", function() {
console.log("网速异常");
})
})
},