liveVideo.vue 42 KB

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