王士厅

fix: 沉浸式播放,断网后上滑,视频无法加载和上滑,恢复网络后视频重新播放,无法上滑切换下一个视频

1 import { Action, 1 import { Action,
2 ContentDetailDTO, ContentDTO, InteractDataDTO, PeopleShipNextListDTO } from 'wdBean/Index'; 2 ContentDetailDTO, ContentDTO, InteractDataDTO, PeopleShipNextListDTO } from 'wdBean/Index';
3 -import { NetworkUtil, WindowModel } from 'wdKit'; 3 +import { EmitterEventId, EmitterUtils, NetworkType, NetworkUtil, WindowModel } from 'wdKit';
4 import { ContentDetailRequest } from 'wdDetailPlayApi/Index' 4 import { ContentDetailRequest } from 'wdDetailPlayApi/Index'
5 import { ResponseDTO } from 'wdNetwork/Index'; 5 import { ResponseDTO } from 'wdNetwork/Index';
6 import { DetailPlayShortVideoPage } from './DetailPlayShortVideoPage' 6 import { DetailPlayShortVideoPage } from './DetailPlayShortVideoPage'
@@ -55,6 +55,7 @@ export struct DetailVideoListPage { @@ -55,6 +55,7 @@ export struct DetailVideoListPage {
55 private AudioSuspension = new AudioSuspensionModel() 55 private AudioSuspension = new AudioSuspensionModel()
56 @State isShowAudioCom: boolean = false 56 @State isShowAudioCom: boolean = false
57 @StorageLink('GestureLoadStrategy') GestureLoadStrategy: number = 0 57 @StorageLink('GestureLoadStrategy') GestureLoadStrategy: number = 0
  58 + @State timer: number = -1
58 59
59 // async getRmhDetail() { 60 // async getRmhDetail() {
60 // // 注册监听网络连接 61 // // 注册监听网络连接
@@ -119,6 +120,30 @@ export struct DetailVideoListPage { @@ -119,6 +120,30 @@ export struct DetailVideoListPage {
119 this.getDetail() 120 this.getDetail()
120 } 121 }
121 122
  123 + // 注册监听网络连接
  124 + EmitterUtils.receiveEvent(EmitterEventId.NETWORK_CONNECTED, (async (str?: string) => {
  125 + if (this.timer) {
  126 + clearTimeout(this.timer)
  127 + }
  128 + this.timer = setTimeout(() => {
  129 + let type: NetworkType | null = null
  130 + if (str) {
  131 + type = JSON.parse(str) as NetworkType
  132 + }
  133 + // 注册监听网络连接
  134 + if (type != NetworkType.TYPE_UNKNOWN) {
  135 + console.log(TAG, '网络连接状态变化', type)
  136 + if(type == NetworkType.TYPE_CELLULAR || type == NetworkType.TYPE_WIFI) {
  137 + if (!this.peopleShipHomeCreatorId) {
  138 + this.queryVideoList()
  139 + } else {
  140 + this.getRmhPublishNexts(this.peopleShipHomeCreatorId, `${this.data[this.currentIndex].newsId}`, 1, 1, 10, systemDateTime.getTime(false));
  141 + }
  142 + }
  143 + }
  144 + }, 1000)
  145 + }))
  146 +
122 } 147 }
123 148
124 149
@@ -443,7 +468,9 @@ export struct DetailVideoListPage { @@ -443,7 +468,9 @@ export struct DetailVideoListPage {
443 .displayCount(1, true) 468 .displayCount(1, true)
444 .onChange((index: number) => { 469 .onChange((index: number) => {
445 this.currentIndex = index 470 this.currentIndex = index
446 - if (this.currentIndex === this.data.length - 1) { 471 + // if (this.currentIndex === this.data.length - 1) {
  472 + // 倒数第二个开始请求下一页数据解决视频上滑卡顿
  473 + if (this.currentIndex === this.data.length - 2) {
447 // TODO:下拉刷新“努力加载中” 474 // TODO:下拉刷新“努力加载中”
448 if (!this.peopleShipHomeCreatorId) { 475 if (!this.peopleShipHomeCreatorId) {
449 this.queryVideoList() 476 this.queryVideoList()
@@ -9,7 +9,9 @@ import { @@ -9,7 +9,9 @@ import {
9 contentListParams, 9 contentListParams,
10 getRecCompInfoParams 10 getRecCompInfoParams
11 } from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest'; 11 } from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';
12 -import { NetworkUtil, Logger, WindowModel, DateTimeUtils, LazyDataSource } from 'wdKit/Index'; 12 +import { NetworkUtil, Logger, WindowModel, DateTimeUtils, LazyDataSource, EmitterUtils,
  13 + EmitterEventId,
  14 + NetworkType} from 'wdKit/Index';
13 import { PictureLoading } from './PictureLoading'; 15 import { PictureLoading } from './PictureLoading';
14 import { DisplayDirection } from 'wdConstant/Index'; 16 import { DisplayDirection } from 'wdConstant/Index';
15 import { window } from '@kit.ArkUI'; 17 import { window } from '@kit.ArkUI';
@@ -70,6 +72,7 @@ export struct VideoChannelDetail { @@ -70,6 +72,7 @@ export struct VideoChannelDetail {
70 @Provide onlyWifiLoadVideo: boolean = false 72 @Provide onlyWifiLoadVideo: boolean = false
71 @Provide toastTextVisible: boolean = false 73 @Provide toastTextVisible: boolean = false
72 @StorageLink('GestureLoadStrategy') GestureLoadStrategy: number = 0 74 @StorageLink('GestureLoadStrategy') GestureLoadStrategy: number = 0
  75 + @State timer: number = -1
73 76
74 autoRefreshChange() { 77 autoRefreshChange() {
75 if (this.topNavIndex === 0 && !this.isRequesting) { 78 if (this.topNavIndex === 0 && !this.isRequesting) {
@@ -140,6 +143,25 @@ export struct VideoChannelDetail { @@ -140,6 +143,25 @@ export struct VideoChannelDetail {
140 aboutToAppear() { 143 aboutToAppear() {
141 this.getDetail() 144 this.getDetail()
142 // Logger.info(TAG, 'aboutToAppear'); 145 // Logger.info(TAG, 'aboutToAppear');
  146 + // 注册监听网络连接
  147 + EmitterUtils.receiveEvent(EmitterEventId.NETWORK_CONNECTED, (async (str?: string) => {
  148 + if (this.timer) {
  149 + clearTimeout(this.timer)
  150 + }
  151 + this.timer = setTimeout(() => {
  152 + let type: NetworkType | null = null
  153 + if (str) {
  154 + type = JSON.parse(str) as NetworkType
  155 + }
  156 + // 注册监听网络连接
  157 + if (type != NetworkType.TYPE_UNKNOWN) {
  158 + console.log(TAG, '网络连接状态变化', type)
  159 + if(type == NetworkType.TYPE_CELLULAR || type == NetworkType.TYPE_WIFI) {
  160 + this.getRecCompInfo()
  161 + }
  162 + }
  163 + }, 1000)
  164 + }))
143 } 165 }
144 166
145 aboutToDisappear(): void { 167 aboutToDisappear(): void {
@@ -331,7 +353,9 @@ export struct VideoChannelDetail { @@ -331,7 +353,9 @@ export struct VideoChannelDetail {
331 this.currentIndex = index 353 this.currentIndex = index
332 // console.info('onChange==', index.toString()) 354 // console.info('onChange==', index.toString())
333 355
334 - if (this.currentIndex === this.data.length - 1) { 356 + // if (this.currentIndex === this.data.length - 1) {
  357 + // 倒数第二个开始请求下一页数据解决视频上滑卡顿
  358 + if (this.currentIndex === this.data.length - 2) {
335 this.pageNum++ 359 this.pageNum++
336 this.refreshTime = new Date().getTime() 360 this.refreshTime = new Date().getTime()
337 this.loadStrategy = 'push_up' 361 this.loadStrategy = 'push_up'