liveVideo.vue 43 KB

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