html.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <!doctypehtml>
  2. <html lang="en">
  3. <head>
  4. <title>
  5. 实现类似BiLiBiLi的播放浮层控制
  6. </title>
  7. <meta charset="utf-8">
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  9. <meta name="viewport"
  10. content="width=device-width,initial-scale=1.0,user-scalable=no">
  11. <link rel="stylesheet"
  12. href="//cdn.jsdelivr.net/bootstrap/3.3.6/css/bootstrap.min.css">
  13. <style type="text/css">
  14. html {
  15. fon-family: sans-serif;
  16. -ms-text-size-adjust: 100%;
  17. -webkit-text-size-adjust: 100%;
  18. font-size: 62.5%;
  19. -webkit-tap-highlight-color: transparent
  20. }
  21. body {
  22. font-family: 'HelveticaNeue',
  23. '\5FAE\8F6F\96C5\9ED1',
  24. '\9ED1\4F53',
  25. sans-serif;
  26. letter-spacing: .01rem;
  27. font-size: 15px;
  28. line-height: 1.75em;
  29. color: #3A4145;
  30. -webkit-font-feature-settings: 'kern' 1;
  31. -moz-font-feature-settings: 'kern' 1;
  32. -o-font-feature-settings: 'kern' 1;
  33. }
  34. h1 {
  35. padding-top: 40px;
  36. text-align: center;
  37. }
  38. .main {
  39. max-width: 720px;
  40. margin: 80px auto;
  41. text-align: center;
  42. }
  43. .mainvideo {
  44. max-width: 100%;
  45. height: auto;
  46. }
  47. </style>
  48. <script src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script>
  49. </head>
  50. <body class="doc">
  51. <h1>
  52. 实现类似BiLiBiLi的播放浮层控制
  53. </h1>
  54. <div class="main">
  55. <video controls
  56. poster="https://img1.wxzxzj.com/vpc-example-cover-your-name-c.png"
  57. src="https://media.vued.vanthink.cn/sparkle_your_name_am360p.mp4"/>
  58. </div>
  59. <script type="text/javascript">
  60. var mediaList = [
  61. {
  62. src: 'https://media.vued.vanthink.cn/CJ7%20-%20Trailer.mp4',
  63. cover: 'https://img1.wxzxzj.com/vpc-example-cover-CJ7-c.jpg',
  64. title: '长江七号-周星驰导演作品,关于外星人的童话故事',
  65. },
  66. {
  67. src: 'https://media.vued.vanthink.cn/sparkle_your_name_am360p.mp4',
  68. cover: 'https://img1.wxzxzj.com/vpc-example-cover-your-name-c.png',
  69. title: '你的名字-新海诚导演作品,穿越彼此的身体,遇见不可思议',
  70. },
  71. {
  72. src: 'https://media.vued.vanthink.cn/the_garden_of_words_trailer_english__1080p.mp4',
  73. cover: 'https://img1.wxzxzj.com/vpc-example-cover-the-garden-c.jpg',
  74. title: '言叶之庭-新海诚导演作品,下雨天静谧的动静也有唯美的相遇',
  75. }]
  76. $(function () {
  77. var $video = document.querySelector('video')
  78. console.log($video)
  79. var index = 1
  80. function playNext () {
  81. if (index === 2) {
  82. index = 0
  83. } else {
  84. index += 1
  85. }
  86. setMediaSession(index)
  87. $video.src = mediaList[index].src
  88. $video.play()
  89. }
  90. function playPrev () {
  91. if (index === 0) {
  92. index = 2
  93. } else {
  94. index -= 1
  95. }
  96. setMediaSession(index)
  97. $video.src = mediaList[index].src
  98. $video.play()
  99. }
  100. initMediaSession()
  101. function setMediaSession (index) {
  102. if ('mediaSession' in navigator) {
  103. var data = mediaList[index]
  104. navigator.mediaSession.metadata = new MediaMetadata({
  105. title: data.title,
  106. artist: data.director,
  107. artwork: [{
  108. src: data.cover,
  109. sizes: '192x192',
  110. },{
  111. src: data.cover,
  112. sizes: '192x192',
  113. }],
  114. })
  115. }
  116. }
  117. function initMediaSession () {
  118. if ('mediaSession' in navigator) {
  119. var ms = navigator.mediaSession
  120. setMediaSession(1)
  121. ms.setActionHandler('play', function () {
  122. console.log(3333)
  123. $video.play()
  124. })
  125. ms.setActionHandler('nexttrack', function () {
  126. console.log(3333)
  127. playNext()
  128. })
  129. ms.setActionHandler('previoustrack', function () {
  130. playPrev()
  131. })
  132. //navigator.mediaSession.setActionHandler('pause',function(){/*Codeexcerpted.*/});
  133. //navigator.mediaSession.setActionHandler('seekbackward',function(){/*Codeexcerpted.*/});
  134. //navigator.mediaSession.setActionHandler('seekforward',function(){/*Codeexcerpted.*/});
  135. //navigator.mediaSession.setActionHandler('previoustrack',function(){/*Codeexcerpted.*/});
  136. //navigator.mediaSession.setActionHandler('nexttrack',function(){/*Codeexcerpted.*/});
  137. }
  138. }
  139. })
  140. </script>
  141. </body>
  142. </html>