张家口产业监测
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.8 KiB

2 years ago
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>前端播放m3u8格式视频</title>
<link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet">
<script src='https://vjs.zencdn.net/7.4.1/video.js'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js" type="text/javascript"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<!-- videojs-contrib-hls 用于在电脑端播放 如果只需手机播放可以不引入 -->
</head>
<body>
<style>
.video-js .vjs-tech {position: relative !important;}
</style>
<div style="float: left;">
<ul id="r_ullist">
</ul>
</div>
<div style="float: left; width: 100px; height: 100px;">
</div>
<div style="float: left;">
<video id="myVideo"
class="video-js vjs-default-skin vjs-big-play-centered"
controls
preload="auto"
style='width: 800px;height: auto'>
<!-- <source id="source" src="http://218.11.12.60:30001/live/78.m3u8" type="application/x-mpegURL"></source> -->
<source id="source" src="http://218.11.12.60:30001/live/1248.m3u8" type="application/x-mpegURL"></source>
</video>
</div>
<!-- <button onclick="videoqihuan()">切换</button> -->
</body>
<script>
// videojs 简单使用
var myVideo = videojs('myVideo', {
bigPlayButton: true,
textTrackDisplay: false,
posterImage: false,
errorDisplay: false,
autoplay: true,
});
// 切换视频
function videoqihuan(src) {
var changeVideo = function (vdoSrc) {
if (/\.m3u8$/.test(vdoSrc)) { //判断视频源是否是m3u8的格式
myVideo.src({
src: vdoSrc,
type: 'application/x-mpegURL' //在重新添加视频源的时候需要给新的type的值
})
} else {
myVideo.src(vdoSrc)
}
myVideo.load();
myVideo.play();
}
changeVideo(src);
}
var videosz = [
{
"id": 1248,
"videoName": "沙滩娱乐",
"httpurl": "http://218.11.12.60:30001/live/1248.m3u8"
},
{
"id": 1249,
"videoName": "游客中心东北角",
"httpurl": "http://218.11.12.60:30001/live/1249.m3u8"
}
];
L_videoList();
/**
* 左侧视频列表
*/
function L_videoList(){
var html = "";
for(var i= 0;i<videosz.length;i++){
var httpurl =videosz[i].httpurl;
var videoName = videosz[i].videoName;
html += "<li style='cursor:pointer' onclick='videoqihuan(\""+httpurl+"\")'>"+videoName+"</li>";
}
$("#r_ullist").html(html);
}
</script>