30piece.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>30</title>
  8. <script src="static/js/vue.js"></script>
  9. <script src="static/js/data.js"></script>
  10. <link href="static/css/video-js.css" rel="stylesheet">
  11. <link rel="stylesheet" href="static/css/swiper-bundle.min.css" />
  12. <script src="static/js/videojs.min.js"></script>
  13. <script src='static/js/videojs.js'></script>
  14. <script src="static/js/jquery.min.js"></script>
  15. <script src="static/js/swiper-bundle.min.js"></script>
  16. <style>
  17. html,
  18. body {
  19. position: relative;
  20. height: 100%;
  21. padding: 0;
  22. margin: 0;
  23. }
  24. body {
  25. background: #eee;
  26. font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  27. font-size: 14px;
  28. color: #000;
  29. margin: 0;
  30. padding: 0;
  31. }
  32. .swiper {
  33. width: 100%;
  34. height: 100%;
  35. }
  36. .swiper-slide {
  37. text-align: center;
  38. font-size: 18px;
  39. background: #fff;
  40. /* Center slide text vertically */
  41. display: -webkit-box;
  42. display: -ms-flexbox;
  43. display: -webkit-flex;
  44. display: flex;
  45. -webkit-box-pack: center;
  46. -ms-flex-pack: center;
  47. -webkit-justify-content: center;
  48. justify-content: center;
  49. -webkit-box-align: center;
  50. -ms-flex-align: center;
  51. -webkit-align-items: center;
  52. align-items: center;
  53. }
  54. .swiper-slide img {
  55. display: block;
  56. width: 100%;
  57. height: 100%;
  58. object-fit: cover;
  59. }
  60. .swiper-button-prev,
  61. .swiper-button-next {
  62. width: 70px;
  63. height: 100px;
  64. color: #fff;
  65. background: rgba(255, 255, 255, .5)
  66. }
  67. .swiper-button-prev:after,
  68. .swiper-button-next:after {
  69. font-size: 50px;
  70. font-weight: bold;
  71. }
  72. .box {
  73. width: 100vw;
  74. height: 100vh;
  75. text-align: center;
  76. overflow: hidden;
  77. }
  78. .video_list {
  79. width: 100%;
  80. height: 100%;
  81. padding: 0 10px;
  82. box-sizing: border-box;
  83. display: flex;
  84. justify-content: space-between;
  85. align-items: center;
  86. flex-wrap: wrap;
  87. }
  88. .video_item {
  89. position: relative;
  90. width: 15%;
  91. height: 18%;
  92. /* width: 254px;
  93. height: 318px; */
  94. margin: 7px 15px;
  95. }
  96. .video_item .poster {
  97. width: 100%;
  98. height: 100%;
  99. /* width: 254px;
  100. height: 318px; */
  101. }
  102. .video_item .play {
  103. width: 60px;
  104. height: 60px;
  105. position: absolute;
  106. top: 0;
  107. left: 0;
  108. right: 0;
  109. bottom: 0;
  110. margin: auto;
  111. }
  112. .player_box {
  113. position: relative;
  114. width: 100vw;
  115. height: 100vh;
  116. overflow: hidden;
  117. }
  118. .video-js .vjs-big-play-button {
  119. /* 中间大的播放按钮 */
  120. font-size: 3.5em;
  121. line-height: 3.5em;
  122. height: 3.5em;
  123. width: 3.5em;
  124. -webkit-border-radius: 2.5em;
  125. -moz-border-radius: 2.5em;
  126. border-radius: 2.5em;
  127. background-color: rgba(115, 133, 159, .5);
  128. border-width: 0.12em;
  129. margin-top: -1.25em;
  130. margin-left: -1.75em;
  131. }
  132. /* 中间的播放箭头 */
  133. .vjs-big-play-button .vjs-icon-placeholder {
  134. font-size: 1.63em;
  135. }
  136. .video-js.vjs-playing .vjs-tech {
  137. pointer-events: auto;
  138. }
  139. /* 视频暂停时显示播放按钮 */
  140. .video-js.vjs-paused .vjs-big-play-button {
  141. display: block;
  142. }
  143. .video-js {
  144. /* 给.video-js设置字体大小以统一各浏览器样式表现,因为video.js采用的是em单位 */
  145. font-size: 20px;
  146. }
  147. .vjs-slider-bar {
  148. width: 30px;
  149. }
  150. .video-js button {
  151. outline: none;
  152. }
  153. /*添加的退出组件*/
  154. .vjs-my-components {
  155. display: flex;
  156. justify-content: center;
  157. align-items: center;
  158. margin-right: 30px;
  159. }
  160. .vjs-my-components:hover {
  161. cursor: pointer;
  162. }
  163. </style>
  164. </head>
  165. <body>
  166. <div id="app" class="box">
  167. <div class="swiper mySwiper">
  168. <div class="swiper-wrapper">
  169. <div class="swiper-slide" v-for="(item,i) in videoList" :key="i">
  170. <div class="video_list" v-show="!showPlayer">
  171. <div class="video_item" v-for="(temp,idx) in item" :key="idx" @click="playVideo(idx,item)">
  172. <img :src="temp.img" alt="" class="poster">
  173. <img src="https://s1.ax1x.com/2023/05/26/p9b4EPe.png" alt="" class="play">
  174. </div>
  175. </div>
  176. </div>
  177. </div>
  178. <div class="swiper-button-next"></div>
  179. <div class="swiper-button-prev"></div>
  180. </div>
  181. <div v-show="showPlayer" class="player_box">
  182. <video ref='video' id="myVideos" class="video-js vjs-default-skin vjs-big-play-centered "
  183. style="width:100vw;height:100vh;overflow: hidden;">
  184. </video>
  185. </div>
  186. </div>
  187. <script>
  188. // import { dataList } from './static/js/data.js';
  189. var vm = new Vue({
  190. el: '#app',
  191. data: {
  192. player: null, //视频播放器
  193. videoUrl: '', //当前播放的视频资源
  194. showPlayer: false, //是否显示播放器
  195. videoList: dataList()
  196. },
  197. created() {
  198. // console.log(dataList)
  199. },
  200. methods: {
  201. // 播放视频
  202. playVideo(idx, all) {
  203. let _this = this;
  204. let list = all
  205. let i =idx
  206. _this.showPlayer = true
  207. $(function () {
  208. _this.$nextTick(() => {
  209. _this.player = videojs(`myVideos`, {
  210. autoplay: false, //自动播放
  211. controls: true,//控制条
  212. language: "en",// 初始化语言
  213. preload: "auto",// 预加载
  214. sources: [{ src: list[i].url, type: 'video/mp4' }], //视频资源
  215. poster: list[i].img, //背景图
  216. fluid: true, // 自适应宽高
  217. controlBar: {
  218. FullscreenToggle: false, //隐藏自带全屏按钮
  219. children: [
  220. { name: 'playToggle' }, // 播放按钮
  221. { name: 'currentTimeDisplay' }, // 当前已播放时间
  222. { name: 'progressControl' }, // 播放进度条
  223. { name: 'durationDisplay' }, // 总时间
  224. {
  225. name: 'volumePanel', // 音量控制
  226. inline: false, // 不使用水平方式
  227. },
  228. ]
  229. }
  230. }, function () {
  231. //添加退出按钮 begin
  232. var baseComponent = videojs.getComponent('Component')
  233. var myComponent = videojs.extend(baseComponent, {
  234. constructor: function (player, options) {
  235. baseComponent.apply(this, arguments)
  236. this.on('click', this.clickIcon)
  237. },
  238. createEl: function () {
  239. var divObj = videojs.dom.createEl('div', {
  240. // Prefixing classes of elements within a player with "vjs-"
  241. // is a convention used in Video.js.
  242. // 给元素加vjs-开头的样式名,是videojs内置样式约定俗成的做法
  243. className: 'vjs-my-components',
  244. innerHTML:
  245. '<span style="font-size:20px;font-weight:bold;">退出</span>'
  246. })
  247. return divObj
  248. },
  249. clickIcon: function () {
  250. //退出全屏
  251. _this.exitFullscreen(videojs('myVideos'))
  252. // _this.exitFullscreen(videojs(`myVideos${type}`))
  253. }
  254. })
  255. videojs.registerComponent('myComponent', myComponent)
  256. // 找到 controlBar 节点,添加控件
  257. _this.player.getChild('controlBar').addChild('myComponent')
  258. //添加退出按钮 end
  259. //监听视频加载
  260. this.on("canplaythrough", function () {
  261. this.play()
  262. // console.log("视频源数据加载完成")
  263. })
  264. //监听播放
  265. this.on("playing", function () {
  266. _this.fullScreen(videojs('myVideos'))
  267. // _this.fullScreen(videojs(`myVideos${type}`))
  268. });
  269. //监听播放结束
  270. this.on('ended', function () {
  271. i++;
  272. //播放到最后一个
  273. if (i >= list.length) {
  274. //继续从头播放
  275. i = 0;
  276. //回到列表页
  277. // _this.showPlayer = false;
  278. // this.dispose();
  279. // $(".player_box").html('<video id="myVideos" class="video-js vjs-default-skin vjs-big-play-centered "> <source type="video/mp4" src="" /></video>');
  280. // return
  281. }
  282. var videoObj = list[i];
  283. this.src({ src: videoObj.url });
  284. this.play();
  285. })
  286. });
  287. })
  288. });
  289. },
  290. //全屏播放
  291. fullScreen(ele) {
  292. if (ele.requestFullscreen) {
  293. ele.requestFullscreen();
  294. } else if (ele.mozRequestFullScreen) {
  295. ele.mozRequestFullScreen();
  296. } else if (ele.webkitRequestFullscreen) {
  297. ele.webkitRequestFullscreen();
  298. } else if (ele.msRequestFullscreen) {
  299. ele.msRequestFullscreen();
  300. }
  301. return true;
  302. },
  303. //退出全屏
  304. exitFullscreen(ele) {
  305. if (ele.exitFullScreen) {
  306. ele.exitFullScreen();
  307. } else if (ele.mozCancelFullScreen) {
  308. ele.mozCancelFullScreen();
  309. } else if (ele.webkitExitFullscreen) {
  310. ele.webkitExitFullscreen();
  311. } else if (ele.msExitFullscreen) {
  312. ele.msExitFullscreen();
  313. } else {
  314. this.showPlayer = false;
  315. this.player.dispose();
  316. $(".player_box").html('<video id="myVideos" class="video-js vjs-default-skin vjs-big-play-centered "> <source type="video/mp4" src="" /></video>');
  317. }
  318. return true;
  319. }
  320. }
  321. });
  322. </script>
  323. <script>
  324. var swiper = new Swiper(".mySwiper", {
  325. // autoplay: true,
  326. loop: true, // 循环模式选项
  327. resistanceRatio: 0,//值越大空白越大
  328. navigation: {
  329. nextEl: ".swiper-button-next",
  330. prevEl: ".swiper-button-prev",
  331. },
  332. });
  333. //监听是否全屏
  334. $(window).resize(function () {
  335. if (checkIsFullScreen()) {
  336. console.log('进入全屏')
  337. } else {
  338. //销毁播放器,显示列表
  339. if (vm.player) {
  340. vm.player.dispose();
  341. $(".player_box").html('<video id="myVideos" class="video-js vjs-default-skin vjs-big-play-centered "> <source type="video/mp4" src="" /></video>');
  342. }
  343. vm.showPlayer = false
  344. }
  345. });
  346. //是否全屏
  347. function checkIsFullScreen() {
  348. var isFullScreen = document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen;
  349. return isFullScreen == undefined ? false : isFullScreen;
  350. }
  351. </script>
  352. <SCRIPT language="JavaScript">
  353. //禁止使用右键
  354. function click() {
  355. if (event.button == 2) {
  356. }
  357. }
  358. document.onmousedown = click
  359. </SCRIPT>
  360. </body>
  361. </html>