liveVideo.vue 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  1. <template>
  2. <view class="video-player-container">
  3. <!-- 直播状态显示 -->
  4. <view class="videolist" v-if="liveItem.status == 2" :class="[isFullscreen ? 'screen' : '', liveItem && liveItem.showType == 2 ? 'vertical' : '']">
  5. <view class="video" :class="{'video_row': liveItem.showType == 1, 'video_col': liveItem.showType == 2,'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 style="width:46rpx;height: 46rpx;" src="/static/images/live/full_screen.png" />
  25. </view>
  26. <!-- 全屏返回按钮 - 只在全屏状态下显示 -->
  27. <view v-if="isFullscreen" class="fullscreen-exit-btn" @click="exitFullscreen">
  28. <image src="/static/images/live/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" @click="handleAgreement">
  83. <text>分享给好友</text>
  84. </view>
  85. </button>
  86. <view class="action-button reserve-button" @click="handleAgreement">
  87. <image class="button-icon " 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. try {
  396. //const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  397. if (livePlayerContext) {
  398. if (this.isHarmonyOS) {
  399. console.log('鸿蒙系统播放直播');
  400. console.log('直播流URL:', this.liveItem.livingUrl);
  401. console.log('直播ID:', this.liveId);
  402. // 鸿蒙系统特殊处理:延迟播放并添加重试机制
  403. setTimeout(() => {
  404. this.harmonyOSLivePlay(livePlayerContext, 0);
  405. }, 500);
  406. } else {
  407. livePlayerContext.play();
  408. }
  409. }
  410. } catch (e) {
  411. console.warn('createLivePlayerContext API不可用,使用video标签播放:', e);
  412. // 降级使用video标签播放
  413. const videoId = `myVideo_${this.liveId}`;
  414. const videoContext = uni.createVideoContext(videoId, this);
  415. if (videoContext) {
  416. videoContext.play();
  417. }
  418. }
  419. } else if (this.liveItem.status == 1 && this.liveItem.previewUrl) {
  420. const videoId = `myVideo_${this.liveId}`;
  421. const videoContext = uni.createVideoContext(videoId, this);
  422. if (videoContext) {
  423. if (this.isHarmonyOS) {
  424. // 鸿蒙系统特殊处理:延迟播放
  425. setTimeout(() => {
  426. videoContext.play();
  427. }, 500);
  428. } else {
  429. videoContext.play();
  430. }
  431. }
  432. } else if (this.liveItem.liveType === 2 && this.liveItem.videoUrl && this.liveItem.status == 2) {
  433. // 检查是否为HLS格式的视频流
  434. const isHLS = this.liveItem.videoUrl.toLowerCase().endsWith('.m3u8');
  435. console.log('视频URL:', this.liveItem.videoUrl, '是否为HLS格式:', isHLS);
  436. if (isHLS && !this.isHarmonyOS) {
  437. // 非鸿蒙系统:HLS格式使用live-player播放
  438. const livePlayerId = `myLivePlayer_${this.liveId}`;
  439. try {
  440. //const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  441. if (livePlayerContext) {
  442. livePlayerContext.play();
  443. }
  444. } catch (e) {
  445. console.warn('createLivePlayerContext API不可用,使用video标签播放:', e);
  446. // 降级使用video标签播放
  447. const videoId = `myVideo_${this.liveId}`;
  448. const videoContext = uni.createVideoContext(videoId, this);
  449. if (videoContext) {
  450. videoContext.play();
  451. }
  452. }
  453. } else {
  454. // 鸿蒙系统或普通视频格式:使用video组件播放
  455. const videoId = `myVideo_${this.liveId}`;
  456. const videoContext = uni.createVideoContext(videoId, this);
  457. if (videoContext) {
  458. if (this.isHarmonyOS) {
  459. // 鸿蒙系统特殊处理:延迟播放
  460. setTimeout(() => {
  461. console.log('鸿蒙系统执行 video 组件播放');
  462. videoContext.play();
  463. }, 500);
  464. } else {
  465. videoContext.play();
  466. }
  467. }
  468. }
  469. } // 回放视频使用video
  470. else if (this.liveItem.liveType === 3 && this.liveItem.videoUrl && this.liveItem.status == 4) {
  471. // 检查是否为HLS格式的视频流
  472. const isHLS = this.liveItem.videoUrl.toLowerCase().endsWith('.m3u8');
  473. console.log('回放视频URL:', this.liveItem.videoUrl, '是否为HLS格式:', isHLS);
  474. if (isHLS && !this.isHarmonyOS) {
  475. // 非鸿蒙系统:HLS格式使用live-player播放
  476. const livePlayerId = `myLivePlayer_${this.liveId}`;
  477. try {
  478. //const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  479. if (livePlayerContext) {
  480. livePlayerContext.play();
  481. }
  482. } catch (e) {
  483. console.warn('createLivePlayerContext API不可用,使用video标签播放:', e);
  484. // 降级使用video标签播放
  485. const videoId = `myVideo_${this.liveId}`;
  486. const videoContext = uni.createVideoContext(videoId, this);
  487. if (videoContext) {
  488. videoContext.play();
  489. }
  490. }
  491. } else {
  492. // 鸿蒙系统或普通视频格式:使用video组件播放
  493. const videoId = `myVideo_${this.liveId}`;
  494. const videoContext = uni.createVideoContext(videoId, this);
  495. if (videoContext) {
  496. if (this.isHarmonyOS) {
  497. // 鸿蒙系统特殊处理:延迟播放
  498. setTimeout(() => {
  499. console.log('鸿蒙系统执行 video 组件播放');
  500. videoContext.play();
  501. }, 500);
  502. } else {
  503. videoContext.play();
  504. }
  505. }
  506. }
  507. }
  508. } catch (error) {
  509. console.error('播放视频失败:', error);
  510. // 播放失败时尝试重试
  511. if (this.videoRetryCount < this.maxRetryCount) {
  512. this.videoRetryCount++;
  513. console.log(`视频播放失败,${this.videoRetryCount}秒后重试`);
  514. setTimeout(() => {
  515. this.playVideo();
  516. }, this.videoRetryCount * 1000);
  517. }
  518. }
  519. },
  520. pauseVideo() {
  521. if (!this.liveItem) return;
  522. try {
  523. // 直播流使用live-player
  524. if (this.liveItem.status == 1) {
  525. const videoId = `myVideo_${this.liveId}`;
  526. const videoContext = uni.createVideoContext(videoId, this);
  527. if (videoContext) {
  528. videoContext.pause();
  529. }
  530. } else if (this.liveItem.status == 2) {
  531. if (this.liveItem.liveType === 1) {
  532. const livePlayerId = `myLivePlayer_${this.liveId}`;
  533. try {
  534. //const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  535. if (livePlayerContext) {
  536. livePlayerContext.pause();
  537. }
  538. } catch (e) {
  539. console.warn('createLivePlayerContext API不可用,使用video标签暂停:', e);
  540. // 降级使用video标签暂停
  541. const videoId = `myVideo_${this.liveId}`;
  542. const videoContext = uni.createVideoContext(videoId, this);
  543. if (videoContext) {
  544. videoContext.pause();
  545. }
  546. }
  547. } else if (this.liveItem.liveType === 2) {
  548. const videoId = `myVideo_${this.liveId}`;
  549. const videoContext = uni.createVideoContext(videoId, this);
  550. if (videoContext) {
  551. videoContext.pause();
  552. }
  553. }
  554. }
  555. } catch (error) {
  556. console.error('暂停视频失败:', error);
  557. }
  558. },
  559. // 视频错误处理
  560. videoError(e, liveItem) {
  561. if (!liveItem || !this.liveId) return;
  562. // 初始化重试计数
  563. if (this.videoRetryCounts[liveItem.liveId] === undefined) {
  564. this.videoRetryCounts[liveItem.liveId] = 0;
  565. }
  566. // 限制重试次数
  567. if (this.videoRetryCounts[liveItem.liveId] >= 3) {
  568. console.error(`直播间 ${this.liveId} 视频加载失败,停止重试`);
  569. // 显示错误提示
  570. uni.showToast({
  571. title: '视频加载失败,请检查网络',
  572. icon: 'none',
  573. duration: 2000
  574. });
  575. return;
  576. }
  577. this.videoRetryCounts[this.liveId]++;
  578. // 延迟重试
  579. setTimeout(() => {
  580. if (this.liveId === this.liveId) {
  581. console.log(`第${this.videoRetryCounts[this.liveId]}次重试播放视频`);
  582. this.playVideo();
  583. }
  584. }, 2000);
  585. }, // 视频暂停
  586. onVideoPause(e) {
  587. if (this.liveItem.liveType === 2) {
  588. const videoId = `myVideo_${this.liveId}`;
  589. const videoContext = uni.createVideoContext(videoId, this);
  590. setTimeout(() => {
  591. videoContext.play();
  592. }, 100);
  593. }
  594. // 暂停时保存进度
  595. this.saveVideoProgress();
  596. }, //直播、录播缓冲
  597. getLiveInternetTraffic() {
  598. if (!this.liveId) return;
  599. const currentTime = (this.stayTime / this.liveItem.duration) * 100;
  600. const param = {
  601. userId: this.userData.userId || '',
  602. liveId: this.liveId || '',
  603. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  604. internetTraffic: this.totalTraffic
  605. };
  606. liveInternetTraffic(param);
  607. },
  608. startTimer() {
  609. this.startTime = Date.now();
  610. this.lookTimer = setInterval(() => {
  611. this.stayTime = Math.floor((Date.now() - this.startTime) / 1000);
  612. }, 1000);
  613. },
  614. // 计算流量
  615. // calculateTraffic(bitrate) {
  616. // const currentTime = Date.now();
  617. // const duration = (currentTime - this.startTime) / 1000; // 持续时间(秒)
  618. // // 流量 = 码率 × 时间
  619. // // 码率单位: bps, 时间单位: 秒, 流量单位: 比特
  620. // const trafficBits = bitrate * duration;
  621. // // 转换为字节
  622. // this.totalTraffic = trafficBits / 8;
  623. // this.getLiveInternetTraffic();
  624. // },
  625. // 计算流量
  626. calculateTraffic(bitrate) {
  627. const currentTime = Date.now();
  628. const duration = (currentTime - this.startTime) / 1000; // 持续时间(秒)
  629. // 流量 = 码率 × 时间
  630. // 码率单位: bps, 时间单位: 秒, 流量单位: 比特
  631. const trafficBits = bitrate * duration;
  632. // 转换为字节
  633. this.totalTraffic = trafficBits / 8;
  634. // 调用流量上报接口
  635. this.getLiveInternetTraffic();
  636. },
  637. //直播计算流量
  638. // startTrafficCalculation(bitrate) {
  639. // if (this.trafficTimer) {
  640. // clearInterval(this.trafficTimer);
  641. // this.trafficTimer = null;
  642. // }
  643. // this.startTime = Date.now();
  644. // var that = this;
  645. // this.trafficTimer = setInterval(() => {
  646. // that.calculateTraffic(bitrate);
  647. // }, 10000); // 每10秒计算一次
  648. // },
  649. startTrafficCalculation() {
  650. if (this.trafficTimer) {
  651. clearInterval(this.trafficTimer);
  652. this.trafficTimer = null;
  653. }
  654. this.startTime = Date.now();
  655. var that = this;
  656. // 计算码率
  657. let bitrate = this.calculateBitrate();
  658. this.trafficTimer = setInterval(() => {
  659. that.calculateTraffic(bitrate);
  660. }, 10000); // 每10秒计算一次
  661. },
  662. // 清理所有定时器
  663. clearAllTimers() {
  664. if (this.trafficTimer) {
  665. clearInterval(this.trafficTimer);
  666. this.trafficTimer = null;
  667. }
  668. if (this.lookTimer) {
  669. clearInterval(this.lookTimer);
  670. this.lookTimer = null;
  671. }
  672. if (this.liveStartTimer) {
  673. clearInterval(this.liveStartTimer);
  674. this.liveStartTimer = null;
  675. }
  676. }, // 计算码率
  677. calculateBitrate() {
  678. // 如果接口返回了视频文件大小和时长,使用这些数据计算码率
  679. if (this.liveItem.videoFileSize && this.liveItem.videoDuration) {
  680. // 码率 = 文件大小(字节) / 时长(秒) × 8 (转换为bps) × 5
  681. const calculatedBitrate = (this.liveItem.videoFileSize / this.liveItem.videoDuration) * 8 * 5;
  682. console.log(
  683. `使用接口数据计算码率: ${calculatedBitrate} bps (文件大小: ${this.liveItem.videoFileSize} 字节, 时长: ${this.liveItem.videoDuration} 秒)`
  684. );
  685. return calculatedBitrate;
  686. } else {
  687. // 如果任一字段为空,使用默认码率 1500 bps
  688. console.log('接口数据不完整,使用默认码率: 1500 bps');
  689. return 800;
  690. }
  691. },
  692. // 回放、预告缓冲
  693. getInternetTraffic() {
  694. if (!this.liveId || !this.liveId || !this.userData.userId || !this.uuId) return;
  695. const currentTime = (this.stayTime / this.liveItem.duration) * 100;
  696. const param = {
  697. videoType: this.liveItem.videoType,
  698. videoId: this.liveItem.videoId,
  699. userId: this.userData.userId,
  700. liveId: this.liveId,
  701. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  702. duration: this.liveItem.duration,
  703. bufferRate: currentTime
  704. };
  705. if (this.liveItem.status == 1) {
  706. param.videoType = this.liveItem.previewVideoType || '';
  707. param.videoId = this.liveItem.previewVideoId || '';
  708. }
  709. if (this.liveItem.liveType == 1) {
  710. param.bufferRate = this.totalTraffic;
  711. }
  712. internetTraffic(param);
  713. },
  714. saveVideoProgress() {
  715. if (this.videoProgressKey) {
  716. uni.setStorage({
  717. key: this.videoProgressKey,
  718. data: this.videoCurrentTime,
  719. success: () => {},
  720. fail: (err) => {
  721. console.error('保存视频进度失败:', err);
  722. }
  723. });
  724. }
  725. },
  726. getTimeDifferenceInSeconds(createTimeStr, useServerTime) {
  727. // 参数检查,确保createTimeStr不为undefined或null
  728. if (!createTimeStr) {
  729. return 0;
  730. }
  731. const createTime = new Date(String(createTimeStr).replace(/-/g, '/'));
  732. const now = new Date();
  733. const timeDiffMs = now - createTime;
  734. const timeDiffSeconds = Math.floor(timeDiffMs / 1000);
  735. return Math.max(0, timeDiffSeconds);
  736. },
  737. // onVideoWaiting(e) {
  738. // // console.log('视频等待加载', e);
  739. // if (this.liveItem.liveType == 2) {
  740. // this.startTrafficCalculation(this.bitrate);
  741. // } else {
  742. // let that = this;
  743. // if (this.trafficInterval) {
  744. // clearInterval(this.trafficInterval);
  745. // this.trafficInterval = null;
  746. // }
  747. // this.trafficInterval = setInterval(function() {
  748. // that.getInternetTraffic();
  749. // }, 10000);
  750. // }
  751. // },
  752. onVideoWaiting(e) {
  753. console.log('视频等待加载', e);
  754. if (this.liveItem.liveType == 2) {
  755. // 修改这里:不再传入固定码率,而是在方法内部计算
  756. this.startTrafficCalculation();
  757. } else {
  758. let that = this;
  759. if (this.trafficInterval) {
  760. clearInterval(this.trafficInterval);
  761. this.trafficInterval = null;
  762. }
  763. this.trafficInterval = setInterval(function() {
  764. that.getInternetTraffic();
  765. }, 10000);
  766. }
  767. },
  768. setVideoProgress() {
  769. console.log('设置视频进度');
  770. // 只有录播和回放需要设置进度
  771. if (this.liveItem.liveType !== 2 && this.liveItem.liveType !== 3) {
  772. return;
  773. }
  774. let currentTime = 0;
  775. if (this.liveItem.liveType === 2) {
  776. // 录播:计算当前时间与开始时间的差值,对视频总时长取模
  777. const diff = this.getTimeDifferenceInSeconds(this.liveItem.startTime);
  778. if (diff > this.liveItem.duration) {
  779. console.log("开始断点续播了")
  780. const storedProgress = uni.getStorageSync(this.videoProgressKey) || 0;
  781. console.log("开始断点续播了storedProgress", storedProgress)
  782. currentTime = storedProgress >= this.liveItem.duration ? 0 : storedProgress || 0;
  783. console.log("开始断点续播了currentTime", currentTime)
  784. } else {
  785. currentTime = diff % this.liveItem.duration;
  786. }
  787. // currentTime = diff % this.liveItem.duration;
  788. } else if (this.liveItem.liveType === 3) {
  789. // 回放:从存储中获取进度
  790. const storedProgress = uni.getStorageSync(this.videoProgressKey);
  791. currentTime = storedProgress || 0;
  792. }
  793. const videoId = `myVideo_${this.liveId}`;
  794. const videoContext = uni.createVideoContext(videoId, this);
  795. if (videoContext) {
  796. videoContext.seek(currentTime);
  797. }
  798. }, // 视频播放
  799. onVideoPlay(e) {
  800. console.log('视频播放');
  801. //console.log("qxj onVideoPlay");
  802. // 重置手动暂停标志
  803. this.isManualPause = false;
  804. // 清除等待定时器
  805. if (this.waitingTimer) {
  806. clearTimeout(this.waitingTimer);
  807. this.waitingTimer = null;
  808. }
  809. this.waitingStartTime = 0;
  810. this.lastVideoUpdateTime = Date.now(); // 更新最后更新时间
  811. if (this.liveItem.status == 2) {
  812. //this.startCountdown();
  813. // 启动观看时长统计
  814. //this.startWatchDurationTracking();
  815. }
  816. if (this.watchTimeTimer) {
  817. clearInterval(this.watchTimeTimer);
  818. this.watchTimeTimer = null;
  819. this.saveWatchTime();
  820. console.log("视频开始播放")
  821. }
  822. },
  823. // 录播时间点
  824. onVideoMetaLoaded(e) {
  825. console.log("录播时间点", e)
  826. this.videoProgressKey = `videoProgress_${this.liveId}`;
  827. this.setVideoProgress();
  828. },
  829. // 视频时间更新
  830. onVideoTimeUpdate(e) {
  831. // console.log('视频时间更新');
  832. // 获取当前播放时间
  833. this.videoCurrentTime = e.detail.currentTime;
  834. // 每隔10秒保存一次进度(避免频繁存储)
  835. if (Math.floor(this.videoCurrentTime) % 10 === 0) {
  836. this.saveVideoProgress();
  837. }
  838. // 更新视频最后更新时间(用于检测是否卡顿)
  839. this.lastVideoUpdateTime = Date.now();
  840. // 如果视频在更新,说明没有卡顿,清除等待状态
  841. if (this.waitingStartTime && this.lastVideoUpdateTime - this.waitingStartTime < 1000) {
  842. // 视频在1秒内恢复了,清除等待定时器
  843. if (this.waitingTimer) {
  844. clearTimeout(this.waitingTimer);
  845. this.waitingTimer = null;
  846. }
  847. this.waitingStartTime = 0;
  848. }
  849. // 使用服务器时间判断直播是否结束
  850. const diff = this.getTimeDifferenceInSeconds(this.liveItem.serviceStartTime, true)
  851. if (diff >= this.liveItem.duration) {
  852. if (!this.hasPlayback) {
  853. this.generating = false;
  854. this.hasPlayback = true;
  855. this.isEnd = true;
  856. }
  857. }
  858. },
  859. // 初始化组件 - 增强版本
  860. async initializeComponent() {
  861. console.log('初始化视频组件:', {
  862. liveId: this.liveId,
  863. liveItem: this.liveItem,
  864. 状态: this.liveItem?.status,
  865. 开始时间: this.liveItem?.startTime
  866. });
  867. // 检测系统类型
  868. this.detectSystemType();
  869. this.uuId = generateRandomString(16);
  870. this.localIsAgreement = uni.getStorageSync('isAgreement');
  871. // 立即检查当前状态并启动相应功能
  872. if (this.liveItem?.status === 1 && this.liveItem.startTime) {
  873. console.log('检测到预告状态,立即启动倒计时');
  874. this.startLiveCountdown();
  875. } else if (this.liveItem?.status === 2) {
  876. this.startTimeTimer(this.liveItem);
  877. // 鸿蒙系统特殊处理:延迟播放以确保组件完全初始化
  878. if (this.isHarmonyOS) {
  879. console.log('鸿蒙系统延迟播放以确保组件初始化');
  880. setTimeout(() => {
  881. console.log('鸿蒙系统执行播放');
  882. this.playVideo();
  883. }, 1000);
  884. } else {
  885. this.playVideo();
  886. }
  887. }
  888. this.startTimer();
  889. this.hasInitialized = true;
  890. // 鸿蒙系统额外UI更新
  891. if (this.isHarmonyOS) {
  892. console.log('鸿蒙系统组件初始化完成 - 额外UI更新');
  893. // 延迟100ms后强制UI更新
  894. setTimeout(() => {
  895. this.$forceUpdate();
  896. console.log('鸿蒙系统组件初始化后强制UI更新');
  897. // 再延迟100ms后再次强制UI更新
  898. setTimeout(() => {
  899. this.$forceUpdate();
  900. console.log('鸿蒙系统组件初始化后二次强制UI更新');
  901. }, 100);
  902. }, 100);
  903. }
  904. },
  905. // 启动直播倒计时 - 增强版本
  906. startLiveCountdown() {
  907. console.log('启动直播倒计时:', this.liveItem.startTime);
  908. // 清理旧定时器
  909. if (this.liveStartTimer) {
  910. clearInterval(this.liveStartTimer);
  911. this.liveStartTimer = null;
  912. }
  913. // 立即计算一次倒计时
  914. this.liveCountdown = this.handleTime(this.liveItem.startTime, 0);
  915. console.log('初始倒计时:', this.liveCountdown);
  916. // 如果倒计时已结束,触发直播开始事件
  917. if (!this.liveCountdown) {
  918. console.log('倒计时已结束,触发直播开始');
  919. this.$emit('liveStart');
  920. return;
  921. }
  922. // 启动定时器
  923. this.liveStartTimer = setInterval(() => {
  924. const previousCountdown = JSON.stringify(this.liveCountdown);
  925. this.liveCountdown = this.handleTime(this.liveItem.startTime, 0);
  926. // 记录倒计时变化(用于调试)
  927. if (previousCountdown !== JSON.stringify(this.liveCountdown)) {
  928. console.log('倒计时更新:', this.liveCountdown);
  929. }
  930. if (!this.liveCountdown) {
  931. console.log('倒计时结束,触发直播开始');
  932. this.$emit('liveStart');
  933. clearInterval(this.liveStartTimer);
  934. this.liveStartTimer = null;
  935. }
  936. }, 1000);
  937. },
  938. // 时间处理函数 - 增强错误处理
  939. handleTime(time, duration) {
  940. if (!time) {
  941. console.error('时间参数为空');
  942. return false;
  943. }
  944. let timeStamp;
  945. try {
  946. if (typeof time === 'number' && time > 0 && time < 9999999999999) {
  947. timeStamp = time;
  948. } else if (typeof time === 'string' && time.trim() !== '') {
  949. const isoTime = time.replace(' ', 'T');
  950. const date = new Date(isoTime);
  951. if (!isNaN(date.getTime())) {
  952. timeStamp = date.getTime();
  953. } else {
  954. console.error('无效的日期格式:', time);
  955. return false;
  956. }
  957. } else {
  958. console.error('time参数必须是有效的时间戳或日期字符串');
  959. return false;
  960. }
  961. const targetTimestamp = timeStamp + duration * 60 * 1000;
  962. const currentTimestamp = Date.now();
  963. const timeDiffMs = targetTimestamp - currentTimestamp;
  964. if (timeDiffMs <= 0) {
  965. return false;
  966. }
  967. const hours = Math.floor(timeDiffMs / (1000 * 60 * 60));
  968. const minutes = Math.floor((timeDiffMs % (1000 * 60 * 60)) / (1000 * 60));
  969. const seconds = Math.floor((timeDiffMs % (1000 * 60)) / 1000);
  970. const formatNum = (num) => num.toString().padStart(2, '0');
  971. return {
  972. hours: formatNum(hours),
  973. minutes: formatNum(minutes),
  974. seconds: formatNum(seconds),
  975. rawMs: timeDiffMs // 添加原始毫秒数用于调试
  976. };
  977. } catch (error) {
  978. console.error('时间处理错误:', error);
  979. return false;
  980. }
  981. },
  982. // 其他方法保持不变...
  983. startTimeTimer(item) {
  984. if (!item) return;
  985. this.calculateTimeDiff(item);
  986. if (item.timeTimer) {
  987. clearInterval(item.timeTimer);
  988. }
  989. item.timeTimer = setInterval(() => {
  990. this.calculateTimeDiff(item);
  991. }, 1000);
  992. },
  993. calculateTimeDiff(item) {
  994. if (!item.startTime) return;
  995. const time = new Date(item.startTime.replace(/-/g, '/'));
  996. if (isNaN(time.getTime())) return;
  997. const now = new Date();
  998. let diffMs = Math.max(0, now.getTime() - time.getTime());
  999. const totalSeconds = Math.floor(diffMs / 1000);
  1000. const hours = this.padZero(Math.floor(totalSeconds / 3600));
  1001. const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60));
  1002. const seconds = this.padZero(totalSeconds % 60);
  1003. this.diffTotalTime = `${hours}:${minutes}:${seconds}`;
  1004. },
  1005. padZero(num) {
  1006. return num < 10 ? `0${num}` : num;
  1007. },
  1008. // 清理方法
  1009. cleanup() {
  1010. if (this.liveStartTimer) {
  1011. clearInterval(this.liveStartTimer);
  1012. this.liveStartTimer = null;
  1013. }
  1014. if (this.trafficTimer) {
  1015. clearInterval(this.trafficTimer);
  1016. this.trafficTimer = null;
  1017. }
  1018. if (this.trafficInterval) {
  1019. clearInterval(this.trafficInterval);
  1020. this.trafficInterval = null;
  1021. }
  1022. if (this.lookTimer) {
  1023. clearInterval(this.lookTimer);
  1024. this.lookTimer = null;
  1025. }
  1026. if (this.liveItem && this.liveItem.timeTimer) {
  1027. clearInterval(this.liveItem.timeTimer);
  1028. this.liveItem.timeTimer = null;
  1029. }
  1030. },
  1031. // 检查网络状态
  1032. checkNetworkStatus() {
  1033. uni.getNetworkType({
  1034. success: (res) => {
  1035. console.log('网络状态:', res.networkType);
  1036. if (res.networkType === 'none') {
  1037. console.error('网络连接已断开');
  1038. uni.showToast({
  1039. title: '网络连接已断开,请检查网络设置',
  1040. icon: 'none',
  1041. duration: 3000
  1042. });
  1043. }
  1044. }
  1045. });
  1046. },
  1047. // 防止双击
  1048. preventDoubleClick(e) {
  1049. console.log('preventDoubleClick triggered');
  1050. }
  1051. }
  1052. };
  1053. </script>
  1054. <style scoped lang="scss">
  1055. .video-player-container {
  1056. width: 100%;
  1057. height: 100%;
  1058. position: relative;
  1059. }
  1060. .videolist {
  1061. position: relative;
  1062. height: 100vh;
  1063. width: 100%;
  1064. &.screen {
  1065. width: 100%;
  1066. height: 100%;
  1067. }
  1068. &.vertical {
  1069. height: auto;
  1070. }
  1071. .video {
  1072. height: 100vh;
  1073. width: 100%;
  1074. .item {
  1075. width: 100%;
  1076. height: 100%;
  1077. }
  1078. .time {
  1079. color: #ffffff;
  1080. font-size: 20rpx;
  1081. margin-left: 10rpx;
  1082. }
  1083. .look-time {
  1084. position: absolute;
  1085. left: 10vh;
  1086. bottom: 24rpx;
  1087. font-size: 20rpx;
  1088. background-color: rgba(57, 57, 57, 0.6);
  1089. border-radius: 15rpx;
  1090. z-index: 999999 !important;
  1091. padding: 10rpx 16rpx;
  1092. color: #fff;
  1093. }
  1094. .end {
  1095. position: absolute;
  1096. top: 50%;
  1097. left: 50%;
  1098. transform: translate(-50%, -50%);
  1099. font-size: 36rpx;
  1100. color: #fff;
  1101. }
  1102. .lable {
  1103. position: absolute;
  1104. top: 50rpx;
  1105. right: 16rpx;
  1106. background-color: rgba(57, 57, 57, 0.6);
  1107. padding: 4rpx 10rpx;
  1108. color: #fff;
  1109. border-radius: 15rpx;
  1110. }
  1111. }
  1112. .video_row {
  1113. position: absolute;
  1114. top: 380rpx;
  1115. max-height: 450rpx;
  1116. z-index: 99;
  1117. &.video_col {
  1118. position: static;
  1119. }
  1120. /* ==== 全屏模式样式 ==== */
  1121. &.fullscreen-mode {
  1122. // position: fixed !important;
  1123. // top: 0 !important;
  1124. // left: 0 !important;
  1125. top: 0;
  1126. width: 0;
  1127. height: auto;
  1128. z-index: 99999 !important;
  1129. background-color: #000 !important;
  1130. transform: rotate(90deg) !important;
  1131. transform-origin: center center !important;
  1132. // transform: rotate(0) ;
  1133. // transform: rotate(90deg) translateY(-100%) !important;
  1134. // transform-origin: left top !important;
  1135. .item {
  1136. position: absolute;
  1137. bottom: 0;
  1138. width: 100vh !important;
  1139. height: 100vw !important;
  1140. // transform: rotate(-90deg) !important;
  1141. transform-origin: center center !important;
  1142. object-fit: contain !important;
  1143. }
  1144. .custom-controls {
  1145. transform: rotate(-90deg) !important;
  1146. transform-origin: center center !important;
  1147. bottom: auto !important;
  1148. top: 40rpx !important;
  1149. right: 40rpx !important;
  1150. }
  1151. .fullscreen-exit-btn {
  1152. position: fixed;
  1153. bottom: 40rpx;
  1154. left: 82vh;
  1155. display: flex;
  1156. flex-direction: column;
  1157. align-items: center;
  1158. justify-content: center;
  1159. z-index: 100001;
  1160. background: rgba(57, 57, 57, 0.6);
  1161. border-radius: 40rpx;
  1162. padding: 20rpx 24rpx;
  1163. transition: all 0.3s ease;
  1164. &:active {
  1165. transform: scale(0.95);
  1166. background: rgba(50, 50, 50, 0.6);
  1167. }
  1168. .exit-fullscreen-icon {
  1169. width: 40rpx;
  1170. height: 40rpx;
  1171. margin-bottom: 10rpx;
  1172. }
  1173. .exit-text {
  1174. color: #ffffff;
  1175. font-size: 22rpx;
  1176. white-space: nowrap;
  1177. }
  1178. }
  1179. }
  1180. /* 全屏按钮样式优化 */
  1181. .custom-controls {
  1182. position: absolute;
  1183. bottom: 10%;
  1184. right: 40rpx;
  1185. z-index: 99999999;
  1186. background: rgba(0, 0, 0, 0.6);
  1187. border-radius: 50%;
  1188. width: 80rpx;
  1189. height: 80rpx;
  1190. display: flex;
  1191. align-items: center;
  1192. justify-content: center;
  1193. transition: all 0.3s ease;
  1194. &:active {
  1195. transform: scale(0.95);
  1196. background: rgba(0, 0, 0, 0.8);
  1197. }
  1198. }
  1199. }
  1200. .video_col {
  1201. position: relative;
  1202. // height: 60vh;
  1203. // max-height: 60vh;
  1204. z-index: 99;
  1205. }
  1206. }
  1207. // 重置按钮样式
  1208. .button-reset {
  1209. background-color: transparent !important;
  1210. padding: 0 !important;
  1211. line-height: 1 !important;
  1212. margin: 0 !important;
  1213. width: auto !important;
  1214. font-weight: 500 !important;
  1215. border-radius: none !important;
  1216. &::after {
  1217. border: none !important;
  1218. padding: 0 !important;
  1219. margin: 0 !important;
  1220. }
  1221. }
  1222. .trailer-box {
  1223. width: calc(100% - 80rpx);
  1224. background: #333333;
  1225. border-radius: 24rpx;
  1226. position: absolute;
  1227. top: 320rpx;
  1228. left: 50%;
  1229. transform: translateX(-50%);
  1230. display: flex;
  1231. flex-direction: column;
  1232. align-items: center;
  1233. color: #fff;
  1234. padding: 20rpx;
  1235. z-index: 99;
  1236. box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.12);
  1237. transition: box-shadow 0.3s ease;
  1238. .trailer-video {
  1239. width: 100%;
  1240. height: 400rpx;
  1241. }
  1242. .trailer-placeholder {
  1243. margin-bottom: 40rpx;
  1244. width: 240rpx;
  1245. height: 240rpx;
  1246. }
  1247. .countdown-container {
  1248. margin: 20rpx 0;
  1249. display: flex;
  1250. flex-direction: column;
  1251. align-items: center;
  1252. .live-name {
  1253. font-weight: 600;
  1254. font-size: 36rpx;
  1255. }
  1256. .countdown-display {
  1257. display: flex;
  1258. align-items: center;
  1259. margin: 30rpx 0;
  1260. .countdown-label {
  1261. font-size: 24rpx;
  1262. color: #999999;
  1263. }
  1264. .countdown-separator {
  1265. font-size: 24rpx;
  1266. color: #999999;
  1267. }
  1268. .countdown-unit {
  1269. width: 40rpx;
  1270. height: 40rpx;
  1271. background: #4D4D4D;
  1272. border-radius: 8rpx;
  1273. text-align: center;
  1274. overflow: hidden;
  1275. margin: 0 8rpx;
  1276. font-weight: 500;
  1277. font-size: 28rpx;
  1278. color: #FFFFFF;
  1279. line-height: 40rpx;
  1280. }
  1281. }
  1282. }
  1283. .trailer-actions {
  1284. display: flex;
  1285. justify-content: center;
  1286. align-items: center;
  1287. .action-button {
  1288. width: 280rpx;
  1289. height: 72rpx;
  1290. display: flex;align-items: center;
  1291. justify-content: center;
  1292. border-radius: 36rpx;
  1293. color: #fff;
  1294. margin-right: 18rpx;
  1295. &:last-child{
  1296. margin-right: 0;
  1297. }
  1298. &.reserve-button {
  1299. background: linear-gradient(136deg, #38D97D 0%, #02B176 100%);
  1300. }
  1301. &:not(.reserve-button) {
  1302. background: #F4A007;
  1303. }
  1304. .button-icon {
  1305. width: 32rpx;
  1306. height: 32rpx;
  1307. margin-right: 8rpx;
  1308. }
  1309. }
  1310. }
  1311. .no-live-title {
  1312. margin-top: 30rpx;
  1313. font-size: 42rpx;
  1314. font-weight: 500;
  1315. }
  1316. }
  1317. </style>