SimpleDanmakuPlayer.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="player-container" :class="{ fullscreen: isFullscreen }">
  3. <!-- 视频 -->
  4. <video
  5. :src="videoSrc"
  6. controls
  7. :autoplay="false"
  8. style="width: 100%; height: 100%;"
  9. ></video>
  10. <!-- 普通全屏按钮(非全屏时显示,H5/App 都可用) -->
  11. <!-- 注意:这个按钮不能放在 cover-view 里,否则 App 上可能不响应 -->
  12. <!-- 所以我们只在非全屏、非 App/小程序时显示它 -->
  13. <!-- #ifndef APP-PLUS && !MP-WEIXIN -->
  14. <view v-if="!isFullscreen" class="btn" @click.stop="enterFullscreen">🔲</view>
  15. <!-- #endif -->
  16. <!-- 覆盖层:仅用于 App 和小程序 -->
  17. <!-- #ifdef APP-PLUS || MP-WEIXIN -->
  18. <cover-view class="cover-layer">
  19. <!-- 固定弹幕:不接收点击,透传事件 -->
  20. <cover-view class="fixed-danmaku">我爱弹幕111</cover-view>
  21. <!-- 全屏按钮(非全屏时显示) -->
  22. <cover-view
  23. v-if="!isFullscreen"
  24. class="control-btn"
  25. @click="enterFullscreen"
  26. >🔲</cover-view>
  27. <!-- 退出全屏按钮(全屏时显示) -->
  28. <cover-view
  29. v-if="isFullscreen"
  30. class="control-btn exit"
  31. @click="exitFullscreen"
  32. >◻️</cover-view>
  33. </cover-view>
  34. <!-- #endif -->
  35. <!-- H5 覆盖层(普通 view) -->
  36. <!-- #ifndef APP-PLUS && !MP-WEIXIN -->
  37. <view v-if="isFullscreen" class="h5-cover">
  38. <view class="fixed-danmaku">我爱弹幕111</view>
  39. <view class="control-btn exit" @click="exitFullscreen">◻️</view>
  40. </view>
  41. <!-- #endif -->
  42. </view>
  43. </template>
  44. <script setup>
  45. import { ref } from 'vue'
  46. const videoSrc = 'http://www.w3school.com.cn/i/movie.mp4' // 替换为你的视频地址
  47. const isFullscreen = ref(false)
  48. const enterFullscreen = () => {
  49. isFullscreen.value = true
  50. // #ifdef APP-PLUS
  51. plus.navigator.setFullscreen(true)
  52. // #endif
  53. }
  54. const exitFullscreen = () => {
  55. isFullscreen.value = false
  56. // #ifdef APP-PLUS
  57. plus.navigator.setFullscreen(false)
  58. // #endif
  59. }
  60. </script>
  61. <style scoped>
  62. .player-container {
  63. position: relative;
  64. width: 100%;
  65. height: 240px;
  66. background: #000;
  67. }
  68. .player-container.fullscreen {
  69. position: fixed;
  70. top: 0;
  71. left: 0;
  72. width: 100vw;
  73. height: 100vh;
  74. z-index: 9999;
  75. }
  76. /* ===== App & 小程序:cover-view 方案 ===== */
  77. /* #ifdef APP-PLUS || MP-WEIXIN */
  78. .cover-layer {
  79. position: absolute;
  80. top: 0;
  81. left: 0;
  82. width: 100%;
  83. height: 100%;
  84. /* 关键:默认不拦截事件 */
  85. pointer-events: none;
  86. }
  87. .fixed-danmaku {
  88. position: absolute;
  89. bottom: 100rpx;
  90. left: 50%;
  91. transform: translateX(-50%);
  92. padding: 10rpx 20rpx;
  93. background: rgba(0, 0, 0, 0.6);
  94. color: #fff;
  95. font-size: 28rpx;
  96. border-radius: 10rpx;
  97. white-space: nowrap;
  98. /* 不需要 pointer-events: auto,保持透传 */
  99. }
  100. /* 只有按钮需要接收点击 */
  101. .control-btn {
  102. position: absolute;
  103. right: 16rpx;
  104. bottom: 16rpx;
  105. width: 64rpx;
  106. height: 64rpx;
  107. border-radius: 50%;
  108. background: rgba(0, 0, 0, 0.6);
  109. display: flex;
  110. align-items: center;
  111. justify-content: center;
  112. color: white;
  113. font-size: 28rpx;
  114. /* 关键:只在这里开启事件 */
  115. pointer-events: auto;
  116. }
  117. .control-btn.exit {
  118. /* 退出按钮样式可复用 */
  119. }
  120. /* #endif */
  121. /* ===== H5 方案 ===== */
  122. /* #ifndef APP-PLUS && !MP-WEIXIN */
  123. .h5-cover {
  124. position: absolute;
  125. top: 0;
  126. left: 0;
  127. width: 100%;
  128. height: 100%;
  129. pointer-events: none;
  130. }
  131. .h5-cover .fixed-danmaku {
  132. position: absolute;
  133. bottom: 50px;
  134. left: 50%;
  135. transform: translateX(-50%);
  136. padding: 6px 12px;
  137. background: rgba(0, 0, 0, 0.6);
  138. color: white;
  139. font-size: 16px;
  140. border-radius: 6px;
  141. white-space: nowrap;
  142. }
  143. .h5-cover .control-btn {
  144. position: absolute;
  145. right: 10px;
  146. bottom: 10px;
  147. width: 32px;
  148. height: 32px;
  149. border-radius: 50%;
  150. background: rgba(0, 0, 0, 0.6);
  151. display: flex;
  152. align-items: center;
  153. justify-content: center;
  154. color: white;
  155. font-size: 14px;
  156. pointer-events: auto;
  157. cursor: pointer;
  158. }
  159. /* #endif */
  160. </style>