liveVideo.vue 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. <template>
  2. <view class="video-player-container">
  3. <!-- 直播状态显示 -->
  4. <view class="videolist" v-if="liveItem.status == 2" :class="isFullscreen ? 'screen' : ''">
  5. <view class="video" :class="{'video_row': liveItem.showType == 1,'fullscreen-mode': isFullscreen}">
  6. <!-- 直播 -->
  7. <live-player v-if="liveItem.livingUrl && liveItem.liveType == 1" :id="'myLivePlayer_' + liveId"
  8. :src="liveItem.livingUrl" autoplay mode="live" object-fit="cover" :muted="false"
  9. orientation="vertical" :enable-play-gesture="false" min-cache="1" max-cache="3"
  10. @statechange="onLiveStateChange" @error="onLiveError" class="item"></live-player>
  11. <!-- 录播 -->
  12. <video v-if="liveItem.videoUrl && liveItem.liveType == 2" :id="`myVideo_${liveId}`" :autoplay="true"
  13. class="item" :src="liveItem.videoUrl" :controls="false"
  14. :object-fit="liveItem.showType==2||isFullscreen?'contain':'fill'" :custom-cache="false"
  15. :enable-progress-gesture="false" vslide-gesture-in-fullscreen="false" :show-center-play-btn="false"
  16. :http-cache="false" loop @error="videoError" @timeupdate="onVideoTimeUpdate"
  17. @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause" @play="onVideoPlay"
  18. @waiting="onVideoWaiting" :enable-play-gesture="false" :play-strategy="1"
  19. @dblclick="preventDoubleClick" preload="auto" :enable-stash-buffer="false" :stash-initial-size="0"
  20. :stash-max-size="0" :stash-time="0" type="application/x-mpegURL"></video>
  21. <view v-if="liveItem.videoUrl && liveItem.liveType == 2" class="time"
  22. :class="isFullscreen ? 'look-time' : 'time'">{{ diffTotalTime }}</view>
  23. <view class="custom-controls" @click.stop="toggleFullscreen">
  24. <image src="/static/images/full_screen.png" class="control-icon" />
  25. </view>
  26. <!-- 全屏返回按钮 - 只在全屏状态下显示 -->
  27. <view v-if="isFullscreen" class="fullscreen-exit-btn" @click="exitFullscreen">
  28. <image src="/static/images/half_screen.png" class="exit-fullscreen-icon" />
  29. <text class="exit-text">退出全屏</text>
  30. </view>
  31. </view>
  32. </view>
  33. <!-- 直播结束状态 -->
  34. <view class="videolist" v-if="liveItem.status == 3">
  35. <view class="video" :class="liveItem.showType == 1 ? 'video_row' : ''">
  36. <view class="end">直播已结束</view>
  37. </view>
  38. </view>
  39. <!-- 直播回放状态 -->
  40. <view class="videolist" v-if="liveItem.status == 4">
  41. <view class="video" :class="liveItem.showType == 1 ? 'video_row' : ''">
  42. <!-- 直播回放 -->
  43. <video v-if="liveItem.videoUrl && liveItem.liveType == 3" :id="`myVideo_${liveId}`" class="item"
  44. :src="liveItem.videoUrl" :autoplay="true" :controls="true" object-fit="cover" :custom-cache="false"
  45. :enable-progress-gesture="liveItem.isSpeedAllowed" vslide-gesture-in-fullscreen="true"
  46. :show-center-play-btn="true" :http-cache="false" loop @error="videoError"
  47. @timeupdate="onVideoTimeUpdate" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause"
  48. @play="onVideoPlay" :enable-play-gesture="true" preload="auto" @waiting="onVideoWaiting"
  49. type="application/x-mpegURL"></video>
  50. <view v-if="liveItem.videoUrl && liveItem.liveType == 3" class="lable">直播回放</view>
  51. </view>
  52. </view>
  53. <view class="trailer-box" v-if="liveItem.status == 1">
  54. <video v-if="liveItem.previewUrl" :id="`myVideo_${liveId}`" class="trailer-video" :src="liveItem.previewUrl"
  55. :autoplay="true" loop object-fit="cover" :custom-cache="false" :enable-progress-gesture="false"
  56. vslide-gesture-in-fullscreen="false" :show-center-play-btn="false" :http-cache="false"
  57. @error="videoError" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause" @play="onVideoPlay"
  58. :disable-progress="true" :enable-play-gesture="true" @waiting="onVideoWaiting" preload="auto"
  59. type="application/x-mpegURL" :controls="false"></video>
  60. <image v-if="liveItem.status == 1 && !liveItem.previewUrl" class="trailer-placeholder"
  61. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/no_live.png">
  62. </image>
  63. <view class="countdown-container" v-if="liveItem.status == 1 && liveCountdown">
  64. <view class="live-name">{{ liveItem.liveName }}</view>
  65. <view class="countdown-display">
  66. <text class="countdown-label">距离开播还有</text>
  67. <view class="countdown-unit">
  68. {{ liveCountdown.hours || '00' }}
  69. </view>
  70. <view class="countdown-separator">:</view>
  71. <view class="countdown-unit">
  72. {{ liveCountdown.minutes || '00' }}
  73. </view>
  74. <view class="countdown-separator">:</view>
  75. <view class="countdown-unit">
  76. {{ liveCountdown.seconds || '00' }}
  77. </view>
  78. </view>
  79. </view>
  80. <view class="trailer-actions">
  81. <button open-type="share" class="button-reset share-button">
  82. <view class="action-button mr18" @click="handleAgreement">
  83. <text>分享给好友</text>
  84. </view>
  85. </button>
  86. <view class="action-button reserve-button" @click="handleAgreement">
  87. <image class="button-icon mr8" src="/static/images/trailer.png"></image>
  88. <text>{{ hasSubscribed ? '已预约' : '预约直播'}}</text>
  89. <!-- <text>预约直播</text> -->
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 无直播状态 -->
  94. <view class="trailer-box" v-if="!liveItem">
  95. <image class="img" src="/static/images/no_live.png"></image>
  96. <view class="title">暂无直播</view>
  97. </view>
  98. </view>
  99. </template>
  100. <script>
  101. import {
  102. generateRandomString
  103. } from '@/utils/common.js';
  104. import dayjs from 'dayjs';
  105. import {
  106. internetTraffic,
  107. liveInternetTraffic
  108. } from '@/api/living.js';
  109. import {
  110. getUserInfo
  111. } from '@/api/user';
  112. export default {
  113. name: 'LiveVideoPlayer',
  114. props: {
  115. liveItem: {
  116. type: Object,
  117. default: () => ({})
  118. },
  119. liveId: {
  120. type: [String, Number],
  121. default: ''
  122. },
  123. userData: {
  124. type: Object,
  125. default: () => ({})
  126. },
  127. isAgreement: {
  128. type: Boolean,
  129. default: false
  130. },
  131. hasSubscribed: {
  132. type: Boolean,
  133. default: false
  134. }
  135. },
  136. data() {
  137. return {
  138. videoLoaded: false, // 视频是否加载成功
  139. isManualPause: false, // 是否手动暂停
  140. waitingTimer: null, // 视频等待定时器
  141. waitingStartTime: 0, // 视频等待开始时间
  142. lastVideoUpdateTime: 0, // 视频最后更新时间
  143. trafficStartTime: 0, // 流量计算开始时间
  144. liveBeginWatchTime: 0, //开始观看的时间点 不包含预告
  145. // hasSubscribed: false, // 已成功订阅(永久禁用)
  146. isFullscreen: false,
  147. isVideoRotated: false,
  148. showNonVideoElementsFlag: true,
  149. showCustomControls: true,
  150. videoContext: null,
  151. // 流量计算相关
  152. uuId: '',
  153. totalTraffic: 0,
  154. bitrate: 800,
  155. bitrateLive: 1600,
  156. // 定时器
  157. trafficTimer: null,
  158. liveStartTimer: null,
  159. trafficInterval: null,
  160. lookTimer: null,
  161. // 状态数据
  162. liveCountdown: {},
  163. diffTotalTime: '',
  164. videoCurrentTime: 0,
  165. videoProgressKey: '',
  166. startTime: 0,
  167. stayTime: 0,
  168. // 内部状态跟踪
  169. hasInitialized: false,
  170. lastLiveItemStatus: null
  171. };
  172. },
  173. watch: {
  174. // 深度监听 liveItem 的所有变化
  175. liveItem: {
  176. handler(newVal, oldVal) {
  177. if (newVal && newVal.status === 1 && newVal.startTime) {
  178. // 如果是预告状态且有开始时间,立即启动倒计时
  179. this.startLiveCountdown();
  180. }
  181. },
  182. deep: true,
  183. immediate: true // 立即执行一次
  184. },
  185. // 单独监听 status 变化作为备用
  186. 'liveItem.status': {
  187. handler(newStatus, oldStatus) {
  188. console.log('状态变化:', oldStatus, '->', newStatus);
  189. if (newStatus === 1 && this.liveItem.startTime) {
  190. this.startLiveCountdown();
  191. } else if (newStatus === 2) {
  192. this.startTimeTimer(this.liveItem);
  193. }
  194. },
  195. immediate: true
  196. }
  197. },
  198. async created() {
  199. // 最早的可执行时机
  200. if (this.liveItem && Object.keys(this.liveItem).length > 0) {
  201. await this.initializeComponent();
  202. }
  203. },
  204. // async mounted() {
  205. // await this.initializeComponent();
  206. // },
  207. computed: {
  208. shouldShowNonVideoElements() {
  209. return !this.isFullscreen && this.showNonVideoElementsFlag;
  210. },
  211. // 控制是否显示全屏按钮
  212. shouldShowFullscreenButton() {
  213. return this.liveItem.showType == 1 && !this.isFullscreen;
  214. },
  215. },
  216. beforeUnmount() {
  217. this.cleanup();
  218. // 强制退出全屏
  219. this.isFullscreen = false;
  220. this.showCustomControls = true;
  221. },
  222. methods: {
  223. // 退出全屏
  224. exitFullscreen() {
  225. console.log('执行退出全屏');
  226. this.isFullscreen = false;
  227. // 显示非videolist元素
  228. this.showNonVideoElements();
  229. // 强制页面重排
  230. this.$nextTick(() => {
  231. this.$forceUpdate();
  232. this.$emit('fullscreen-change', this.isFullscreen);
  233. });
  234. },
  235. // 恢复videolist盒子
  236. restoreVideoList() {
  237. this.isVideoRotated = false;
  238. this.isFullscreen = false;
  239. },
  240. // 切换全屏
  241. toggleFullscreen() {
  242. // console.log('自定义全屏按钮被点击');
  243. if (this.isFullscreen) {
  244. // 退出全屏
  245. this.exitFullscreen();
  246. } else {
  247. // 进入全屏
  248. this.enterFullscreen();
  249. }
  250. }, // 进入全屏
  251. enterFullscreen() {
  252. console.log('执行进入全屏');
  253. this.isFullscreen = true;
  254. // 设置横屏样式
  255. this.rotateVideoList();
  256. // 隐藏非videolist元素
  257. this.hideNonVideoElements();
  258. this.$emit('fullscreen-change', this.isFullscreen);
  259. // 强制页面重排
  260. this.$forceUpdate();
  261. },
  262. // 隐藏非videolist元素
  263. hideNonVideoElements() {
  264. this.showNonVideoElementsFlag = false;
  265. console.log('隐藏非视频元素');
  266. },
  267. // 显示非videolist元素
  268. showNonVideoElements() {
  269. this.showNonVideoElementsFlag = true;
  270. },
  271. // 防止默认全屏事件
  272. onFullscreenChange(e) {
  273. // 阻止默认全屏行为
  274. e.preventDefault();
  275. // 如果有video进入全屏,立即退出
  276. if (e.detail && e.detail.fullScreen) {
  277. const videoContext = uni.createVideoContext(`myVideo_${this.liveId}`, this);
  278. if (videoContext) {
  279. setTimeout(() => {
  280. videoContext.exitFullScreen();
  281. }, 100);
  282. }
  283. }
  284. },
  285. // 旋转videolist盒子
  286. rotateVideoList() {
  287. this.isVideoRotated = true;
  288. this.isFullscreen = true;
  289. console.log('视频容器旋转到横屏状态');
  290. },
  291. // 全屏状态变化监听
  292. onFullscreenChange(e) {
  293. console.log('全屏状态变化事件详情:', e);
  294. // 方法1:通过事件参数获取(小程序主要方式)
  295. let fullScreen = false;
  296. // 视频组件的全屏事件参数
  297. if (e.detail && typeof e.detail.fullScreen !== 'undefined') {
  298. fullScreen = e.detail.fullScreen;
  299. console.log('通过e.detail.fullScreen获取全屏状态:', fullScreen);
  300. }
  301. // 其他可能的参数名
  302. else if (e.detail && typeof e.detail.fullscreen !== 'undefined') {
  303. fullScreen = e.detail.fullscreen;
  304. console.log('通过e.detail.fullscreen获取全屏状态:', fullScreen);
  305. }
  306. // 方法2:检测横屏(备用)
  307. else {
  308. // 在小程序环境中,可以通过屏幕方向判断
  309. try {
  310. const systemInfo = uni.getSystemInfoSync();
  311. fullScreen = systemInfo.windowWidth > systemInfo.windowHeight;
  312. console.log('通过屏幕方向判断全屏状态:', fullScreen);
  313. } catch (err) {
  314. console.error('获取系统信息失败:', err);
  315. // 默认使用事件参数
  316. fullScreen = e.detail || false;
  317. }
  318. }
  319. this.isFullscreen = fullScreen;
  320. console.log('最终设置isFullscreen为:', this.isFullscreen);
  321. // 根据全屏状态显示/隐藏自定义控件
  322. this.showCustomControls = !this.isFullscreen;
  323. // 强制UI更新
  324. this.$forceUpdate();
  325. // 全屏时锁定横屏
  326. if (this.isFullscreen) {
  327. this.lockOrientation();
  328. } else {
  329. this.unlockOrientation();
  330. }
  331. },
  332. // 锁定屏幕方向为横屏
  333. lockOrientation() {
  334. // 设置屏幕方向为横屏
  335. try {
  336. // 尝试锁定横屏
  337. plus.screen.lockOrientation('landscape-primary');
  338. } catch (e) {
  339. console.log('锁定屏幕方向失败:', e);
  340. // 备用方案
  341. try {
  342. // 使用 Web API(如果支持)
  343. if (screen.orientation && screen.orientation.lock) {
  344. screen.orientation.lock('landscape');
  345. }
  346. } catch (err) {
  347. console.log('备用方案也失败了:', err);
  348. }
  349. }
  350. }, // 解锁屏幕方向
  351. unlockOrientation() {
  352. try {
  353. plus.screen.unlockOrientation();
  354. } catch (e) {
  355. console.log('解锁屏幕方向失败:', e);
  356. // 备用方案
  357. try {
  358. if (screen.orientation && screen.orientation.unlock) {
  359. screen.orientation.unlock();
  360. }
  361. } catch (err) {
  362. console.log('备用解锁方案也失败了:', err);
  363. }
  364. }
  365. },
  366. handleAgreement() {
  367. console.log('预约直播点击');
  368. this.$emit('agreementClick');
  369. }, // 播放视频
  370. playVideo() {
  371. if (!this.liveItem) {
  372. console.log('liveItem 为空,无法播放视频');
  373. return;
  374. }
  375. try {
  376. // 检查网络状态
  377. this.checkNetworkStatus();
  378. // 鸿蒙系统特殊处理:如果已经标记为需要使用 video 组件
  379. if (this.isHarmonyOS && this.useVideoComponentInstead) {
  380. console.log('鸿蒙系统使用 video 组件播放视频');
  381. const videoId = `myVideo_${this.liveId}`;
  382. const videoContext = uni.createVideoContext(videoId, this);
  383. if (videoContext) {
  384. // 鸿蒙系统特殊处理:延迟播放
  385. setTimeout(() => {
  386. console.log('鸿蒙系统执行 video 组件播放');
  387. videoContext.play();
  388. }, 500);
  389. }
  390. return;
  391. }
  392. // 直播流使用live-player
  393. if (this.liveItem.liveType === 1 && this.liveItem.livingUrl && this.liveItem.status == 2) {
  394. const livePlayerId = `myLivePlayer_${this.liveId}`;
  395. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  396. if (livePlayerContext) {
  397. if (this.isHarmonyOS) {
  398. console.log('鸿蒙系统播放直播');
  399. console.log('直播流URL:', this.liveItem.livingUrl);
  400. console.log('直播ID:', this.liveId);
  401. // 鸿蒙系统特殊处理:延迟播放并添加重试机制
  402. setTimeout(() => {
  403. this.harmonyOSLivePlay(livePlayerContext, 0);
  404. }, 500);
  405. } else {
  406. livePlayerContext.play();
  407. }
  408. }
  409. } else if (this.liveItem.status == 1 && this.liveItem.previewUrl) {
  410. const videoId = `myVideo_${this.liveId}`;
  411. const videoContext = uni.createVideoContext(videoId, this);
  412. if (videoContext) {
  413. if (this.isHarmonyOS) {
  414. // 鸿蒙系统特殊处理:延迟播放
  415. setTimeout(() => {
  416. videoContext.play();
  417. }, 500);
  418. } else {
  419. videoContext.play();
  420. }
  421. }
  422. } else if (this.liveItem.liveType === 2 && this.liveItem.videoUrl && this.liveItem.status == 2) {
  423. // 检查是否为HLS格式的视频流
  424. const isHLS = this.liveItem.videoUrl.toLowerCase().endsWith('.m3u8');
  425. console.log('视频URL:', this.liveItem.videoUrl, '是否为HLS格式:', isHLS);
  426. if (isHLS && !this.isHarmonyOS) {
  427. // 非鸿蒙系统:HLS格式使用live-player播放
  428. const livePlayerId = `myLivePlayer_${this.liveId}`;
  429. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  430. if (livePlayerContext) {
  431. livePlayerContext.play();
  432. }
  433. } else {
  434. // 鸿蒙系统或普通视频格式:使用video组件播放
  435. const videoId = `myVideo_${this.liveId}`;
  436. const videoContext = uni.createVideoContext(videoId, this);
  437. if (videoContext) {
  438. if (this.isHarmonyOS) {
  439. // 鸿蒙系统特殊处理:延迟播放
  440. setTimeout(() => {
  441. console.log('鸿蒙系统执行 video 组件播放');
  442. videoContext.play();
  443. }, 500);
  444. } else {
  445. videoContext.play();
  446. }
  447. }
  448. }
  449. } // 回放视频使用video
  450. else if (this.liveItem.liveType === 3 && this.liveItem.videoUrl && this.liveItem.status == 4) {
  451. // 检查是否为HLS格式的视频流
  452. const isHLS = this.liveItem.videoUrl.toLowerCase().endsWith('.m3u8');
  453. console.log('回放视频URL:', this.liveItem.videoUrl, '是否为HLS格式:', isHLS);
  454. if (isHLS && !this.isHarmonyOS) {
  455. // 非鸿蒙系统:HLS格式使用live-player播放
  456. const livePlayerId = `myLivePlayer_${this.liveId}`;
  457. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  458. if (livePlayerContext) {
  459. livePlayerContext.play();
  460. }
  461. } else {
  462. // 鸿蒙系统或普通视频格式:使用video组件播放
  463. const videoId = `myVideo_${this.liveId}`;
  464. const videoContext = uni.createVideoContext(videoId, this);
  465. if (videoContext) {
  466. if (this.isHarmonyOS) {
  467. // 鸿蒙系统特殊处理:延迟播放
  468. setTimeout(() => {
  469. console.log('鸿蒙系统执行 video 组件播放');
  470. videoContext.play();
  471. }, 500);
  472. } else {
  473. videoContext.play();
  474. }
  475. }
  476. }
  477. }
  478. } catch (error) {
  479. console.error('播放视频失败:', error);
  480. // 播放失败时尝试重试
  481. if (this.videoRetryCount < this.maxRetryCount) {
  482. this.videoRetryCount++;
  483. console.log(`视频播放失败,${this.videoRetryCount}秒后重试`);
  484. setTimeout(() => {
  485. this.playVideo();
  486. }, this.videoRetryCount * 1000);
  487. }
  488. }
  489. },
  490. pauseVideo() {
  491. if (!this.liveItem) return;
  492. try {
  493. // 直播流使用live-player
  494. if (this.liveItem.status == 1) {
  495. const videoId = `myVideo_${this.liveId}`;
  496. const videoContext = uni.createVideoContext(videoId, this);
  497. if (videoContext) {
  498. videoContext.pause();
  499. }
  500. } else if (this.liveItem.status == 2) {
  501. if (this.liveItem.liveType === 1) {
  502. const livePlayerId = `myLivePlayer_${this.liveId}`;
  503. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  504. if (livePlayerContext) {
  505. livePlayerContext.pause();
  506. }
  507. } else if (this.liveItem.liveType === 2) {
  508. const videoId = `myVideo_${this.liveId}`;
  509. const videoContext = uni.createVideoContext(videoId, this);
  510. if (videoContext) {
  511. videoContext.pause();
  512. }
  513. }
  514. }
  515. } catch (error) {
  516. console.error('暂停视频失败:', error);
  517. }
  518. },
  519. // 视频错误处理
  520. videoError(e, liveItem) {
  521. if (!liveItem || !this.liveId) return;
  522. // 初始化重试计数
  523. if (this.videoRetryCounts[liveItem.liveId] === undefined) {
  524. this.videoRetryCounts[liveItem.liveId] = 0;
  525. }
  526. // 限制重试次数
  527. if (this.videoRetryCounts[liveItem.liveId] >= 3) {
  528. console.error(`直播间 ${this.liveId} 视频加载失败,停止重试`);
  529. // 显示错误提示
  530. uni.showToast({
  531. title: '视频加载失败,请检查网络',
  532. icon: 'none',
  533. duration: 2000
  534. });
  535. return;
  536. }
  537. this.videoRetryCounts[this.liveId]++;
  538. // 延迟重试
  539. setTimeout(() => {
  540. if (this.liveId === this.liveId) {
  541. console.log(`第${this.videoRetryCounts[this.liveId]}次重试播放视频`);
  542. this.playVideo();
  543. }
  544. }, 2000);
  545. }, // 视频暂停
  546. onVideoPause(e) {
  547. if (this.liveItem.liveType === 2) {
  548. const videoId = `myVideo_${this.liveId}`;
  549. const videoContext = uni.createVideoContext(videoId, this);
  550. setTimeout(() => {
  551. videoContext.play();
  552. }, 100);
  553. }
  554. // 暂停时保存进度
  555. this.saveVideoProgress();
  556. }, //直播、录播缓冲
  557. getLiveInternetTraffic() {
  558. if (!this.liveId) return;
  559. const currentTime = (this.stayTime / this.liveItem.duration) * 100;
  560. const param = {
  561. userId: this.userData.userId || '',
  562. liveId: this.liveId || '',
  563. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  564. internetTraffic: this.totalTraffic
  565. };
  566. liveInternetTraffic(param);
  567. },
  568. startTimer() {
  569. this.startTime = Date.now();
  570. this.lookTimer = setInterval(() => {
  571. this.stayTime = Math.floor((Date.now() - this.startTime) / 1000);
  572. }, 1000);
  573. },
  574. // 计算流量
  575. // calculateTraffic(bitrate) {
  576. // const currentTime = Date.now();
  577. // const duration = (currentTime - this.startTime) / 1000; // 持续时间(秒)
  578. // // 流量 = 码率 × 时间
  579. // // 码率单位: bps, 时间单位: 秒, 流量单位: 比特
  580. // const trafficBits = bitrate * duration;
  581. // // 转换为字节
  582. // this.totalTraffic = trafficBits / 8;
  583. // this.getLiveInternetTraffic();
  584. // },
  585. // 计算流量
  586. calculateTraffic(bitrate) {
  587. const currentTime = Date.now();
  588. const duration = (currentTime - this.startTime) / 1000; // 持续时间(秒)
  589. // 流量 = 码率 × 时间
  590. // 码率单位: bps, 时间单位: 秒, 流量单位: 比特
  591. const trafficBits = bitrate * duration;
  592. // 转换为字节
  593. this.totalTraffic = trafficBits / 8;
  594. // 调用流量上报接口
  595. this.getLiveInternetTraffic();
  596. },
  597. //直播计算流量
  598. // startTrafficCalculation(bitrate) {
  599. // if (this.trafficTimer) {
  600. // clearInterval(this.trafficTimer);
  601. // this.trafficTimer = null;
  602. // }
  603. // this.startTime = Date.now();
  604. // var that = this;
  605. // this.trafficTimer = setInterval(() => {
  606. // that.calculateTraffic(bitrate);
  607. // }, 10000); // 每10秒计算一次
  608. // },
  609. startTrafficCalculation() {
  610. if (this.trafficTimer) {
  611. clearInterval(this.trafficTimer);
  612. this.trafficTimer = null;
  613. }
  614. this.startTime = Date.now();
  615. var that = this;
  616. // 计算码率
  617. let bitrate = this.calculateBitrate();
  618. this.trafficTimer = setInterval(() => {
  619. that.calculateTraffic(bitrate);
  620. }, 10000); // 每10秒计算一次
  621. },
  622. // 清理所有定时器
  623. clearAllTimers() {
  624. if (this.trafficTimer) {
  625. clearInterval(this.trafficTimer);
  626. this.trafficTimer = null;
  627. }
  628. if (this.lookTimer) {
  629. clearInterval(this.lookTimer);
  630. this.lookTimer = null;
  631. }
  632. if (this.liveStartTimer) {
  633. clearInterval(this.liveStartTimer);
  634. this.liveStartTimer = null;
  635. }
  636. }, // 计算码率
  637. calculateBitrate() {
  638. // 如果接口返回了视频文件大小和时长,使用这些数据计算码率
  639. if (this.liveItem.videoFileSize && this.liveItem.videoDuration) {
  640. // 码率 = 文件大小(字节) / 时长(秒) × 8 (转换为bps) × 5
  641. const calculatedBitrate = (this.liveItem.videoFileSize / this.liveItem.videoDuration) * 8 * 5;
  642. console.log(
  643. `使用接口数据计算码率: ${calculatedBitrate} bps (文件大小: ${this.liveItem.videoFileSize} 字节, 时长: ${this.liveItem.videoDuration} 秒)`
  644. );
  645. return calculatedBitrate;
  646. } else {
  647. // 如果任一字段为空,使用默认码率 1500 bps
  648. console.log('接口数据不完整,使用默认码率: 1500 bps');
  649. return 800;
  650. }
  651. },
  652. // 回放、预告缓冲
  653. getInternetTraffic() {
  654. if (!this.liveId || !this.liveId || !this.userData.userId || !this.uuId) return;
  655. const currentTime = (this.stayTime / this.liveItem.duration) * 100;
  656. const param = {
  657. videoType: this.liveItem.videoType,
  658. videoId: this.liveItem.videoId,
  659. userId: this.userData.userId,
  660. liveId: this.liveId,
  661. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  662. duration: this.liveItem.duration,
  663. bufferRate: currentTime
  664. };
  665. if (this.liveItem.status == 1) {
  666. param.videoType = this.liveItem.previewVideoType || '';
  667. param.videoId = this.liveItem.previewVideoId || '';
  668. }
  669. if (this.liveItem.liveType == 1) {
  670. param.bufferRate = this.totalTraffic;
  671. }
  672. internetTraffic(param);
  673. },
  674. saveVideoProgress() {
  675. if (this.videoProgressKey) {
  676. uni.setStorage({
  677. key: this.videoProgressKey,
  678. data: this.videoCurrentTime,
  679. success: () => {},
  680. fail: (err) => {
  681. console.error('保存视频进度失败:', err);
  682. }
  683. });
  684. }
  685. },
  686. getTimeDifferenceInSeconds(createTimeStr, useServerTime) {
  687. // 参数检查,确保createTimeStr不为undefined或null
  688. if (!createTimeStr) {
  689. return 0;
  690. }
  691. const createTime = new Date(String(createTimeStr).replace(/-/g, '/'));
  692. const now = new Date();
  693. const timeDiffMs = now - createTime;
  694. const timeDiffSeconds = Math.floor(timeDiffMs / 1000);
  695. return Math.max(0, timeDiffSeconds);
  696. },
  697. // onVideoWaiting(e) {
  698. // // console.log('视频等待加载', e);
  699. // if (this.liveItem.liveType == 2) {
  700. // this.startTrafficCalculation(this.bitrate);
  701. // } else {
  702. // let that = this;
  703. // if (this.trafficInterval) {
  704. // clearInterval(this.trafficInterval);
  705. // this.trafficInterval = null;
  706. // }
  707. // this.trafficInterval = setInterval(function() {
  708. // that.getInternetTraffic();
  709. // }, 10000);
  710. // }
  711. // },
  712. onVideoWaiting(e) {
  713. console.log('视频等待加载', e);
  714. if (this.liveItem.liveType == 2) {
  715. // 修改这里:不再传入固定码率,而是在方法内部计算
  716. this.startTrafficCalculation();
  717. } else {
  718. let that = this;
  719. if (this.trafficInterval) {
  720. clearInterval(this.trafficInterval);
  721. this.trafficInterval = null;
  722. }
  723. this.trafficInterval = setInterval(function() {
  724. that.getInternetTraffic();
  725. }, 10000);
  726. }
  727. },
  728. setVideoProgress() {
  729. console.log('设置视频进度');
  730. // 只有录播和回放需要设置进度
  731. if (this.liveItem.liveType !== 2 && this.liveItem.liveType !== 3) {
  732. return;
  733. }
  734. let currentTime = 0;
  735. if (this.liveItem.liveType === 2) {
  736. // 录播:计算当前时间与开始时间的差值,对视频总时长取模
  737. const diff = this.getTimeDifferenceInSeconds(this.liveItem.startTime);
  738. if (diff > this.liveItem.duration) {
  739. console.log("开始断点续播了")
  740. const storedProgress = uni.getStorageSync(this.videoProgressKey) || 0;
  741. console.log("开始断点续播了storedProgress", storedProgress)
  742. currentTime = storedProgress >= this.liveItem.duration ? 0 : storedProgress || 0;
  743. console.log("开始断点续播了currentTime", currentTime)
  744. } else {
  745. currentTime = diff % this.liveItem.duration;
  746. }
  747. // currentTime = diff % this.liveItem.duration;
  748. } else if (this.liveItem.liveType === 3) {
  749. // 回放:从存储中获取进度
  750. const storedProgress = uni.getStorageSync(this.videoProgressKey);
  751. currentTime = storedProgress || 0;
  752. }
  753. const videoId = `myVideo_${this.liveId}`;
  754. const videoContext = uni.createVideoContext(videoId, this);
  755. if (videoContext) {
  756. videoContext.seek(currentTime);
  757. }
  758. }, // 视频播放
  759. onVideoPlay(e) {
  760. console.log('视频播放');
  761. //console.log("qxj onVideoPlay");
  762. // 重置手动暂停标志
  763. this.isManualPause = false;
  764. // 清除等待定时器
  765. if (this.waitingTimer) {
  766. clearTimeout(this.waitingTimer);
  767. this.waitingTimer = null;
  768. }
  769. this.waitingStartTime = 0;
  770. this.lastVideoUpdateTime = Date.now(); // 更新最后更新时间
  771. if (this.liveItem.status == 2) {
  772. //this.startCountdown();
  773. // 启动观看时长统计
  774. //this.startWatchDurationTracking();
  775. }
  776. if (this.watchTimeTimer) {
  777. clearInterval(this.watchTimeTimer);
  778. this.watchTimeTimer = null;
  779. this.saveWatchTime();
  780. console.log("视频开始播放")
  781. }
  782. },
  783. // 录播时间点
  784. onVideoMetaLoaded(e) {
  785. console.log("录播时间点", e)
  786. this.videoProgressKey = `videoProgress_${this.liveId}`;
  787. this.setVideoProgress();
  788. },
  789. // 视频时间更新
  790. onVideoTimeUpdate(e) {
  791. // console.log('视频时间更新');
  792. // 获取当前播放时间
  793. this.videoCurrentTime = e.detail.currentTime;
  794. // 每隔10秒保存一次进度(避免频繁存储)
  795. if (Math.floor(this.videoCurrentTime) % 10 === 0) {
  796. this.saveVideoProgress();
  797. }
  798. // 更新视频最后更新时间(用于检测是否卡顿)
  799. this.lastVideoUpdateTime = Date.now();
  800. // 如果视频在更新,说明没有卡顿,清除等待状态
  801. if (this.waitingStartTime && this.lastVideoUpdateTime - this.waitingStartTime < 1000) {
  802. // 视频在1秒内恢复了,清除等待定时器
  803. if (this.waitingTimer) {
  804. clearTimeout(this.waitingTimer);
  805. this.waitingTimer = null;
  806. }
  807. this.waitingStartTime = 0;
  808. }
  809. // 使用服务器时间判断直播是否结束
  810. const diff = this.getTimeDifferenceInSeconds(this.liveItem.serviceStartTime, true)
  811. if (diff >= this.liveItem.duration) {
  812. if (!this.hasPlayback) {
  813. this.generating = false;
  814. this.hasPlayback = true;
  815. this.isEnd = true;
  816. }
  817. }
  818. },
  819. // 初始化组件 - 增强版本
  820. async initializeComponent() {
  821. console.log('初始化视频组件:', {
  822. liveId: this.liveId,
  823. liveItem: this.liveItem,
  824. 状态: this.liveItem?.status,
  825. 开始时间: this.liveItem?.startTime
  826. });
  827. // 检测系统类型
  828. this.detectSystemType();
  829. this.uuId = generateRandomString(16);
  830. this.localIsAgreement = uni.getStorageSync('isAgreement');
  831. // 立即检查当前状态并启动相应功能
  832. if (this.liveItem?.status === 1 && this.liveItem.startTime) {
  833. console.log('检测到预告状态,立即启动倒计时');
  834. this.startLiveCountdown();
  835. } else if (this.liveItem?.status === 2) {
  836. this.startTimeTimer(this.liveItem);
  837. // 鸿蒙系统特殊处理:延迟播放以确保组件完全初始化
  838. if (this.isHarmonyOS) {
  839. console.log('鸿蒙系统延迟播放以确保组件初始化');
  840. setTimeout(() => {
  841. console.log('鸿蒙系统执行播放');
  842. this.playVideo();
  843. }, 1000);
  844. } else {
  845. this.playVideo();
  846. }
  847. }
  848. this.startTimer();
  849. this.hasInitialized = true;
  850. // 鸿蒙系统额外UI更新
  851. if (this.isHarmonyOS) {
  852. console.log('鸿蒙系统组件初始化完成 - 额外UI更新');
  853. // 延迟100ms后强制UI更新
  854. setTimeout(() => {
  855. this.$forceUpdate();
  856. console.log('鸿蒙系统组件初始化后强制UI更新');
  857. // 再延迟100ms后再次强制UI更新
  858. setTimeout(() => {
  859. this.$forceUpdate();
  860. console.log('鸿蒙系统组件初始化后二次强制UI更新');
  861. }, 100);
  862. }, 100);
  863. }
  864. },
  865. // 启动直播倒计时 - 增强版本
  866. startLiveCountdown() {
  867. console.log('启动直播倒计时:', this.liveItem.startTime);
  868. // 清理旧定时器
  869. if (this.liveStartTimer) {
  870. clearInterval(this.liveStartTimer);
  871. this.liveStartTimer = null;
  872. }
  873. // 立即计算一次倒计时
  874. this.liveCountdown = this.handleTime(this.liveItem.startTime, 0);
  875. console.log('初始倒计时:', this.liveCountdown);
  876. // 如果倒计时已结束,触发直播开始事件
  877. if (!this.liveCountdown) {
  878. console.log('倒计时已结束,触发直播开始');
  879. this.$emit('liveStart');
  880. return;
  881. }
  882. // 启动定时器
  883. this.liveStartTimer = setInterval(() => {
  884. const previousCountdown = JSON.stringify(this.liveCountdown);
  885. this.liveCountdown = this.handleTime(this.liveItem.startTime, 0);
  886. // 记录倒计时变化(用于调试)
  887. if (previousCountdown !== JSON.stringify(this.liveCountdown)) {
  888. console.log('倒计时更新:', this.liveCountdown);
  889. }
  890. if (!this.liveCountdown) {
  891. console.log('倒计时结束,触发直播开始');
  892. this.$emit('liveStart');
  893. clearInterval(this.liveStartTimer);
  894. this.liveStartTimer = null;
  895. }
  896. }, 1000);
  897. },
  898. // 时间处理函数 - 增强错误处理
  899. handleTime(time, duration) {
  900. if (!time) {
  901. console.error('时间参数为空');
  902. return false;
  903. }
  904. let timeStamp;
  905. try {
  906. if (typeof time === 'number' && time > 0 && time < 9999999999999) {
  907. timeStamp = time;
  908. } else if (typeof time === 'string' && time.trim() !== '') {
  909. const isoTime = time.replace(' ', 'T');
  910. const date = new Date(isoTime);
  911. if (!isNaN(date.getTime())) {
  912. timeStamp = date.getTime();
  913. } else {
  914. console.error('无效的日期格式:', time);
  915. return false;
  916. }
  917. } else {
  918. console.error('time参数必须是有效的时间戳或日期字符串');
  919. return false;
  920. }
  921. const targetTimestamp = timeStamp + duration * 60 * 1000;
  922. const currentTimestamp = Date.now();
  923. const timeDiffMs = targetTimestamp - currentTimestamp;
  924. if (timeDiffMs <= 0) {
  925. return false;
  926. }
  927. const hours = Math.floor(timeDiffMs / (1000 * 60 * 60));
  928. const minutes = Math.floor((timeDiffMs % (1000 * 60 * 60)) / (1000 * 60));
  929. const seconds = Math.floor((timeDiffMs % (1000 * 60)) / 1000);
  930. const formatNum = (num) => num.toString().padStart(2, '0');
  931. return {
  932. hours: formatNum(hours),
  933. minutes: formatNum(minutes),
  934. seconds: formatNum(seconds),
  935. rawMs: timeDiffMs // 添加原始毫秒数用于调试
  936. };
  937. } catch (error) {
  938. console.error('时间处理错误:', error);
  939. return false;
  940. }
  941. },
  942. // 其他方法保持不变...
  943. startTimeTimer(item) {
  944. if (!item) return;
  945. this.calculateTimeDiff(item);
  946. if (item.timeTimer) {
  947. clearInterval(item.timeTimer);
  948. }
  949. item.timeTimer = setInterval(() => {
  950. this.calculateTimeDiff(item);
  951. }, 1000);
  952. },
  953. calculateTimeDiff(item) {
  954. if (!item.startTime) return;
  955. const time = new Date(item.startTime.replace(/-/g, '/'));
  956. if (isNaN(time.getTime())) return;
  957. const now = new Date();
  958. let diffMs = Math.max(0, now.getTime() - time.getTime());
  959. const totalSeconds = Math.floor(diffMs / 1000);
  960. const hours = this.padZero(Math.floor(totalSeconds / 3600));
  961. const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60));
  962. const seconds = this.padZero(totalSeconds % 60);
  963. this.diffTotalTime = `${hours}:${minutes}:${seconds}`;
  964. },
  965. padZero(num) {
  966. return num < 10 ? `0${num}` : num;
  967. },
  968. // 清理方法
  969. cleanup() {
  970. if (this.liveStartTimer) {
  971. clearInterval(this.liveStartTimer);
  972. this.liveStartTimer = null;
  973. }
  974. if (this.trafficTimer) {
  975. clearInterval(this.trafficTimer);
  976. this.trafficTimer = null;
  977. }
  978. if (this.trafficInterval) {
  979. clearInterval(this.trafficInterval);
  980. this.trafficInterval = null;
  981. }
  982. if (this.lookTimer) {
  983. clearInterval(this.lookTimer);
  984. this.lookTimer = null;
  985. }
  986. if (this.liveItem && this.liveItem.timeTimer) {
  987. clearInterval(this.liveItem.timeTimer);
  988. this.liveItem.timeTimer = null;
  989. }
  990. },
  991. // 检查网络状态
  992. checkNetworkStatus() {
  993. uni.getNetworkType({
  994. success: (res) => {
  995. console.log('网络状态:', res.networkType);
  996. if (res.networkType === 'none') {
  997. console.error('网络连接已断开');
  998. uni.showToast({
  999. title: '网络连接已断开,请检查网络设置',
  1000. icon: 'none',
  1001. duration: 3000
  1002. });
  1003. }
  1004. }
  1005. });
  1006. }
  1007. }
  1008. };
  1009. </script>
  1010. <style scoped lang="scss">
  1011. .video-player-container {
  1012. width: 100%;
  1013. height: 100%;
  1014. position: relative;
  1015. }
  1016. .videolist {
  1017. position: relative;
  1018. height: 100vh;
  1019. width: 100%;
  1020. &.screen {
  1021. width: 100%;
  1022. height: 100%;
  1023. }
  1024. .video {
  1025. height: 100vh;
  1026. width: 100%;
  1027. .item {
  1028. width: 100%;
  1029. height: 100%;
  1030. }
  1031. .time {
  1032. color: #ffffff;
  1033. font-size: 20rpx;
  1034. margin-left: 10rpx;
  1035. }
  1036. .look-time {
  1037. position: absolute;
  1038. left: 10vh;
  1039. bottom: 24rpx;
  1040. font-size: 20rpx;
  1041. background-color: rgba(57, 57, 57, 0.6);
  1042. border-radius: 15rpx;
  1043. z-index: 999999 !important;
  1044. padding: 10rpx 16rpx;
  1045. color: #fff;
  1046. }
  1047. .end {
  1048. position: absolute;
  1049. top: 50%;
  1050. left: 50%;
  1051. transform: translate(-50%, -50%);
  1052. font-size: 36rpx;
  1053. color: #fff;
  1054. }
  1055. .lable {
  1056. position: absolute;
  1057. top: 50rpx;
  1058. right: 16rpx;
  1059. background-color: rgba(57, 57, 57, 0.6);
  1060. padding: 4rpx 10rpx;
  1061. color: #fff;
  1062. border-radius: 15rpx;
  1063. }
  1064. }
  1065. .video_row {
  1066. position: absolute;
  1067. top: 380rpx;
  1068. max-height: 450rpx;
  1069. z-index: 99;
  1070. /* ==== 全屏模式样式 ==== */
  1071. &.fullscreen-mode {
  1072. // position: fixed !important;
  1073. // top: 0 !important;
  1074. // left: 0 !important;
  1075. top: 0;
  1076. width: 0;
  1077. height: auto;
  1078. z-index: 99999 !important;
  1079. background-color: #000 !important;
  1080. transform: rotate(90deg) !important;
  1081. transform-origin: center center !important;
  1082. // transform: rotate(0) ;
  1083. // transform: rotate(90deg) translateY(-100%) !important;
  1084. // transform-origin: left top !important;
  1085. .item {
  1086. position: absolute;
  1087. bottom: 0;
  1088. width: 100vh !important;
  1089. height: 100vw !important;
  1090. // transform: rotate(-90deg) !important;
  1091. transform-origin: center center !important;
  1092. object-fit: contain !important;
  1093. }
  1094. .custom-controls {
  1095. transform: rotate(-90deg) !important;
  1096. transform-origin: center center !important;
  1097. bottom: auto !important;
  1098. top: 40rpx !important;
  1099. right: 40rpx !important;
  1100. }
  1101. .fullscreen-exit-btn {
  1102. position: fixed;
  1103. bottom: 40rpx;
  1104. left: 82vh;
  1105. display: flex;
  1106. flex-direction: column;
  1107. align-items: center;
  1108. justify-content: center;
  1109. z-index: 100001;
  1110. background: rgba(57, 57, 57, 0.6);
  1111. border-radius: 40rpx;
  1112. padding: 20rpx 24rpx;
  1113. transition: all 0.3s ease;
  1114. &:active {
  1115. transform: scale(0.95);
  1116. background: rgba(50, 50, 50, 0.6);
  1117. }
  1118. .exit-fullscreen-icon {
  1119. width: 40rpx;
  1120. height: 40rpx;
  1121. margin-bottom: 10rpx;
  1122. }
  1123. .exit-text {
  1124. color: #ffffff;
  1125. font-size: 22rpx;
  1126. white-space: nowrap;
  1127. }
  1128. }
  1129. }
  1130. /* 全屏按钮样式优化 */
  1131. .custom-controls {
  1132. position: absolute;
  1133. bottom: 10%;
  1134. right: 40rpx;
  1135. z-index: 99999999;
  1136. background: rgba(0, 0, 0, 0.6);
  1137. border-radius: 50%;
  1138. width: 80rpx;
  1139. height: 80rpx;
  1140. display: flex;
  1141. align-items: center;
  1142. justify-content: center;
  1143. transition: all 0.3s ease;
  1144. .control-icon {
  1145. width: 46rpx;
  1146. height: 46rpx;
  1147. }
  1148. &:active {
  1149. transform: scale(0.95);
  1150. background: rgba(0, 0, 0, 0.8);
  1151. }
  1152. }
  1153. }
  1154. }
  1155. // 重置按钮样式
  1156. .button-reset {
  1157. background-color: transparent !important;
  1158. padding: 0 !important;
  1159. line-height: 1 !important;
  1160. margin: 0 !important;
  1161. width: auto !important;
  1162. font-weight: 500 !important;
  1163. border-radius: none !important;
  1164. &::after {
  1165. border: none !important;
  1166. padding: 0 !important;
  1167. margin: 0 !important;
  1168. }
  1169. }
  1170. .trailer-box {
  1171. width: calc(100% - 80rpx);
  1172. background: #333333;
  1173. border-radius: 24rpx;
  1174. position: absolute;
  1175. top: 320rpx;
  1176. left: 50%;
  1177. transform: translateX(-50%);
  1178. display: flex;
  1179. flex-direction: column;
  1180. align-items: center;
  1181. color: #fff;
  1182. padding: 20rpx;
  1183. z-index: 99;
  1184. box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.12);
  1185. transition: box-shadow 0.3s ease;
  1186. .trailer-video {
  1187. width: 100%;
  1188. height: 400rpx;
  1189. }
  1190. .trailer-placeholder {
  1191. margin-bottom: 40rpx;
  1192. width: 240rpx;
  1193. height: 240rpx;
  1194. }
  1195. .countdown-container {
  1196. margin: 20rpx 0;
  1197. display: flex;
  1198. flex-direction: column;
  1199. align-items: center;
  1200. .live-name {
  1201. font-weight: 600;
  1202. font-size: 36rpx;
  1203. }
  1204. .countdown-display {
  1205. display: flex;
  1206. align-items: center;
  1207. margin: 30rpx 0;
  1208. .countdown-label {
  1209. font-size: 24rpx;
  1210. color: #999999;
  1211. }
  1212. .countdown-separator {
  1213. font-size: 24rpx;
  1214. color: #999999;
  1215. }
  1216. .countdown-unit {
  1217. width: 40rpx;
  1218. height: 40rpx;
  1219. background: #4D4D4D;
  1220. border-radius: 8rpx;
  1221. text-align: center;
  1222. overflow: hidden;
  1223. margin: 0 8rpx;
  1224. font-weight: 500;
  1225. font-size: 28rpx;
  1226. color: #FFFFFF;
  1227. line-height: 40rpx;
  1228. }
  1229. }
  1230. }
  1231. .trailer-actions {
  1232. display: flex;
  1233. justify-content: center;
  1234. align-items: center;
  1235. .action-button {
  1236. width: 280rpx;
  1237. height: 72rpx;
  1238. display: flex;align-items: center;
  1239. justify-content: center;
  1240. border-radius: 36rpx;
  1241. color: #fff;
  1242. &.reserve-button {
  1243. background: linear-gradient(136deg, #38D97D 0%, #02B176 100%);
  1244. }
  1245. &:not(.reserve-button) {
  1246. background: #F4A007;
  1247. }
  1248. .button-icon {
  1249. width: 32rpx;
  1250. height: 32rpx;
  1251. }
  1252. }
  1253. }
  1254. .no-live-title {
  1255. margin-top: 30rpx;
  1256. font-size: 42rpx;
  1257. font-weight: 500;
  1258. }
  1259. }
  1260. </style>