<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>Document</title><linkrel="stylesheet"href="https://at.alicdn.com/t/font_3159328_il2viqh3j9p.css"><linkrel="stylesheet"href="./source/css/font-awesome-4.7.0/css/font-awesome.min.css"/><scriptsrc="./source/js/jquery.min.js"></script><linkhref="./source/css/normalize.css"><style>.player {
margin: 0auto;
padding: 0;
box-sizing: border-box;
width: 100%;
height: auto;
background-color: #FD70A1;
border-radius: 5px;
box-shadow: 1px1px1px1pxrgb(19, 141, 255, 0.2);
}
.player.title {
margin: 0.25em;
color: snow;
}
.player.titlespan {
padding-left: 0.5em;
font-size: 0.8em;
}
.playera {
text-decoration: none;
color: snow;
}
.playervideo {
margin: 0auto;
padding: 0;
box-sizing: border-box;
width: 100%;
height: auto;
}
.controller {
margin: 0auto;
padding: 0;
box-sizing: border-box;
width: 100%;
border-radius: 5px;
box-shadow: 1px1px1px1pxrgb(19, 141, 255, 0.2);
}
.controller.bar {
width: 100%;
height: 0.5em;
background-color: rgba(255, 255, 255, 0.8);
border-radius: 5px;
box-shadow: 0px1px1px0pxrgb(19, 141, 255, 0.2);
}
.controller.bar.line {
height: 100%;
background-color: rgb(34, 200, 255, 1);
border-radius: 5px;
box-shadow: 1px0px1px0pxrgb(19, 141, 255, 0.2);
}
.power {
display: -webkit-inline-flex;
display: inline-flex;
justify-content: space-between;
width: 100%;
}
.controller.basep,
.controller.morep,
.controller.timer {
padding: 01em;
box-sizing: border-box;
height: 1.5em;
color: snow;
line-height: 1.5em;
}
.controller.basepspan,
.controller.morepspan,
.controller.timerspan {
display: inline-block;
font-size: 1.25em;
}
</style></head><body><figure><divclass="player"><divclass="title"><spanclass="iconfont icon-shipin"></span><span>萌狼播放器</span><ahref="https://cnblogs.com/mllt"><small> version:0.1</small></a></div><divclass="svedio"><spanid="tipStop"class="iconfont icon-icon_video noshow"style="font-size:2em"></span><videosrc="./source/video/旋转复制_x264.mp4"></video></div><divclass="controller"><divclass="bar"><divclass="line"></div></div><divclass="power"><divclass="basep"><spanid="state"class="iconfont icon-bofang1"></span><spanid="restate"class="iconfont icon-zanting1"></span></div><divclass="timer"><spanclass="current">00:00:00</span> —— <spanclass="total">00:00:00</span></div><divclass="morep"><spanid="expand"class="iconfont icon-24gf-fullScreenEnter"></span></div></div></div></div></figure><script>varvideo=$("video").get(0); vartimer=false;
video.oncanplay=function () {
$("video").show();
vartotalTime=formatTime(video.duration);
$(".total").html(totalTime); };
video.addEventListener('pause', function () {
console.log('[萌狼工作室]视频被暂停啦~')
$('#state').addClass("icon-bofang1").removeClass("icon-weibiaoti--"); $('#tipStop').addClass('fly-center').removeClass('noshow'); });
video.addEventListener('playing', function () {
console.log('[萌狼工作室]视频开始啦~')
console.log('监听到了播放'+$('#state').hasClass('icon-weibiaoti--'))
$('#state').addClass("icon-weibiaoti--").removeClass("icon-bofang1"); $('#tipStop').addClass('noshow');
});
$("#state").on("click", function () {
if (video.paused) {
video.play(); } else {
video.pause(); }
});
$("#restate").on("click", function () {
video.pause(); $(".line").css("width", 0); video.currentTime=0; $(".current").html(formatTime(video.currentTime)); $('#state').addClass("icon-bofang1").removeClass("icon-weibiaoti--"); });
functionformatTime(time) {
varh=Math.floor(time/3600);
varm=Math.floor(time%3600/60);
vars=Math.floor(time%60);
return (h<10?"0"+h : h) +":"+ (m<10?"0"+m : m) +":"+ (s<10?"0"+s : s);
};
video.ontimeupdate=function () {
varw=video.currentTime/video.duration*100+"%";
$(".line").css("width", w);
$(".current").html(formatTime(video.currentTime));
};
$("#expand").on("click", function () {
vardiv=document.querySelector('.player');
if (!document.webkitIsFullScreen) {
if (div.requestFullscreen) {
div.requestFullscreen(); } elseif (div.webkitRequestFullScreen) {
div.webkitRequestFullScreen(); } elseif (div.mozRequestFullScreen) {
div.mozRequestFullScreen(); } elseif (div.oRequestFullScreen) {
div.oRequestFullScreen(); } elseif (div.msRequestFullscreen) {
div.msRequestFullscreen(); } else {
alert('暂不支持在您的浏览器中全屏');
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen(); } elseif (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen(); } elseif (document.mozCancelFullScreen) {
document.mozCancelFullScreen(); } elseif (document.oCancelFullScreen) {
document.oCancelFullScreen(); } elseif (document.msCancelFullscreen) {
document.msCancelFullscreen(); } else {
alert('暂不支持在您的浏览器中全屏');
}
}
});
document.addEventListener('fullscreenchange', function () {
if (document.webkitIsFullScreen) {
console.log('[萌狼工作室]进入全屏,沉浸体验');
$('.title').addClass("noshow");
$(".controller").addClass("fly");
$("#expand").addClass("icon-24gl-fullScreenEnter").removeClass("icon-24gf-fullScreenEnter");
timer=setInterval(function () {
currentTime=newDate().getTime(); if (currentTime-lastTime>3000) { if (!$('.controller').hasClass('noshow')) {
$('.controller').addClass("noshow");
console.log('切换型监听触发控制栏隐藏');
}
console.log(timer)
}
}, 1000);
} else {
console.log('[萌狼工作室]退出全屏,偷偷看~')
if (timer!=0) {
clearInterval(timer)
console.log('理论上清除了时钟。'+timer)
}
if ($('.title').hasClass("noshow")) {
$('.title').removeClass("noshow");
}
if ($('.controller').hasClass("fly")) {
$(".controller").removeClass("fly");
}
if ($('.controller').hasClass("noshow")) {
$(".controller").removeClass("noshow");
}
if ($("#expand").hasClass("icon-24gl-fullScreenEnter")) {
$("#expand").addClass("icon-24gf-fullScreenEnter").removeClass("icon-24gl-fullScreenEnter");
}
}
})
varlastTime=newDate().getTime(); varcurrentTime=newDate().getTime(); document.addEventListener('mousemove', function () {
if (document.webkitIsFullScreen) {
$('.controller').removeClass("noshow");
lastTime=newDate().getTime(); }
});
video.onended=function () {
video.currentTime=0;
$("#state").addClass("icon-bofang1").removeClass("icon-weibiaoti--");
};
$(".bar").on("click", function (event) {
if (!video.paused) {
video.pause();
}
varoffset=event.offsetX;
varcurrent=offset/$('.bar').width() *video.duration; video.currentTime=current;
console.log('[萌狼播放器]跳转到:'+Math.round(video.currentTime) +"秒")
varw=video.currentTime/video.duration*100+"%";
$(".line").css("width", w);
$(".current").html(formatTime(video.currentTime));
console.log('[萌狼播放器]进度条更新完毕,准备播放');
letplayPromise=video.play()
if (playPromise!==undefined) {
playPromise.then(() => {
video.play()
$('#state').addClass("icon-weibiaoti--").removeClass("icon-bofang1"); console.log('[萌狼播放器]已启动播放,开始观看吧!');
}).catch((e) => {
console.log("[萌狼播放器]#出现错误#:"+e);
console.log("[萌狼播放器]#错误分析#也许视频格式不太支持噢,请尝试转码(可以使用小丸工具箱)");
video.currentTime=0;
$("#state").addClass("icon-bofang1").removeClass("icon-weibiaoti--");
})
}
});
$("video").on("click", function () {
if (video.paused) {
video.play()
$('#tipStop').addClass('noshow');
} else {
video.pause()
}
});
$("#tipStop").on("click", function () {
if (video.paused) {
video.play()
$('#tipStop').addClass('noshow');
} else {
video.pause()
}
})
</script><style>.noshow {
display: none;
}
video::-webkit-media-controls {
display: none!important;
}
.fly {
background-color: rgb(34, 200, 255, 0.5);
position: absolute;
left: 50%;
bottom: 0;
height: 2.5em;
transform: translateX(-50%);
}
.svedio {
position: relative;
font-size: 2em;
color: #FD70A1;
}
.fly-center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 2em;
box-shadow: 1px0px1px0pxrgb(19, 141, 255, 0.5);
}
</style></body></html>