The novice level continues, the big coffee detours
I'm just doing it on the PC side here. I don't know what's wrong with other platforms, but I'm just giving you an idea.
The advantages and disadvantages of videojs, I won't talk about it here, Baidu, everyone, a big explanation, after two days of research, I still don't know how to customize the controls, videojs has a website specially designed for skins (transmission). Magic Array: https://codepen.io/heff/pen/EarCt ), but I still don't know how to do it after working for a long time. Finally, I was inspired by an article. In fact, it is very simple, and violence starts.
Do a picture first
Well, I admit, the style is very low, so I won't complain about the design here.
ok, on the code
myPlayer = videojs('my-video', {
'controls': false, //关闭原来的,不然hover的时候总出来
'BigPlayButton': false,
'loop': true
},function(){
var ctrlBar = createEle(); // 创建一个div节点
this.el().appendChild(ctrlBar); // 添加进去,css设置好样式就可以了
// 初始化音量宽度
var vol = this.volume();
$('.vol-box .vol-on').width(vol * 100);
// 进度条自动前进
this.on('timeupdate', function(){
var curTime = this.currentTime();
var durTime = this.duration();
var w = (curTime/durTime * this.width()).toFixed(2);
$('.progress>p').width(w);
$('.progress>span').css('left', w + 'px');
});
// 播放
this.play();
});
function createEle (){
var _html = `
<div class="progress">
<P></p>
<span></span>
</div>
<div class="ctrls clearfix">
<div class="play-box fl">
<img class="play-img" src="assets/images/vjs-play.png"/>
</div>
<div class="vol-box fr">
<img src="assets/images/vjs-volumn.png"/>
<span class="vol-line"></span>
<span class="vol-on"></span>
<span class="vol-top-line"></span>
</div>
</div>
`;
var ctrlBar = document.createElement('div');
ctrlBar.className = 'vjs-mycontrol-bar';
ctrlBar.innerHTML = _html;
return ctrlBar;
}
Well, it seems that there is no difficulty, just to give you an idea. Of course, the official recommendation is to use Component, so I won't do it here.
For students who want to study, please refer to this article https://www.cnblogs.com/a2502971/p/6691470.html The last section on customizing components is enough