movie.html 12 KB

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