wangliang_wd

feat:优化动态详情页视频展示文图,展示屏蔽全屏功能

1 import router from '@ohos.router'; 1 import router from '@ohos.router';
2 import { BridgeUtil, BridgeWebViewControl, Callback } from 'wdJsBridge'; 2 import { BridgeUtil, BridgeWebViewControl, Callback } from 'wdJsBridge';
3 -import { Logger } from 'wdKit/Index'; 3 +import { Logger, WindowModel } from 'wdKit/Index';
4 import { performJSCallNative } from './JsBridgeBiz'; 4 import { performJSCallNative } from './JsBridgeBiz';
5 import { H5CallNativeType } from './H5CallNativeType'; 5 import { H5CallNativeType } from './H5CallNativeType';
6 import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; 6 import { Message } from 'wdJsBridge/src/main/ets/bean/Message';
7 import { DateTimeUtils } from 'wdKit' 7 import { DateTimeUtils } from 'wdKit'
  8 +import { window } from '@kit.ArkUI';
8 9
9 const TAG = 'WdWebLocalComponent'; 10 const TAG = 'WdWebLocalComponent';
10 11
@@ -33,7 +34,14 @@ export struct WdWebLocalComponent { @@ -33,7 +34,14 @@ export struct WdWebLocalComponent {
33 controller: VideoController = new VideoController() 34 controller: VideoController = new VideoController()
34 @StorageProp('currentBreakpoint') @Watch("currentChanged")currentBreakpoint: string = 'sm'; 35 @StorageProp('currentBreakpoint') @Watch("currentChanged")currentBreakpoint: string = 'sm';
35 36
  37 + @State isFullScreen: boolean = false;
36 currentChanged(){ 38 currentChanged(){
  39 + ///折叠屏转换 暂停播放器
  40 + this.controller.pause()
  41 + this.positionWidth = 0
  42 + this.positionHeight = 0
  43 +
  44 +
37 this.webviewControl.refresh() 45 this.webviewControl.refresh()
38 } 46 }
39 47
@@ -103,82 +111,11 @@ export struct WdWebLocalComponent { @@ -103,82 +111,11 @@ export struct WdWebLocalComponent {
103 111
104 if (this.videoUrl) { 112 if (this.videoUrl) {
105 Stack({ alignContent: Alignment.Bottom }) { 113 Stack({ alignContent: Alignment.Bottom }) {
106 - Video({  
107 - src: this.videoUrl,  
108 - currentProgressRate: this.curRate,  
109 - controller: this.controller  
110 - })  
111 - .borderRadius(5)  
112 - .controls(false)  
113 - .autoPlay(true)  
114 - .objectFit(ImageFit.Contain)  
115 - .onStart(() => {  
116 - this.isPause = false  
117 - })  
118 - .onPause(() => {  
119 - this.isPause = true  
120 - })  
121 - .onPrepared((event) => {  
122 - if (event) {  
123 - this.durationTime = event.duration  
124 - }  
125 - })  
126 - .onUpdate((event) => {  
127 - if (event) {  
128 - this.currentTime = event.time  
129 - }  
130 - })  
131 - Row() {  
132 - Image(this.isPause ? $r('app.media.icon_play') : $r('app.media.icon_pause'))  
133 - .width(24)  
134 - .height(24)  
135 - .onClick(() => {  
136 - if (this.isPause) {  
137 - this.controller.start()  
138 - } else {  
139 - this.controller.pause()  
140 - }  
141 - })  
142 - Row() {  
143 - Text(DateTimeUtils.getFormattedDuration(this.currentTime * 1000))  
144 - .fontSize(12)  
145 - .fontColor(Color.White)  
146 - .fontWeight(600)  
147 - Slider({  
148 - value: this.currentTime,  
149 - min: 0,  
150 - max: this.durationTime  
151 - })  
152 - .width("50%")  
153 - .selectedColor('#ED2800')  
154 - .margin({ left: 4, right: 4 })// .blockStyle({  
155 - // type: SliderBlockType.IMAGE,  
156 - // image: $r('app.media.slider_block')  
157 - // })  
158 - // .blockSize({ width: 18, height: 12 })  
159 - .onChange((value: number, mode: SliderChangeMode) => {  
160 - this.controller.setCurrentTime(value);  
161 - })  
162 - Text(DateTimeUtils.getFormattedDuration(this.durationTime * 1000))  
163 - .fontSize(12)  
164 - .fontColor(Color.White)  
165 - .fontWeight(600)  
166 - }  
167 - .justifyContent(FlexAlign.Center)  
168 -  
169 - Image($r('app.media.icon_full_screen'))  
170 - .width(24)  
171 - .height(24)  
172 - .onClick(() => {  
173 - this.controller.requestFullscreen(true)  
174 - })  
175 - }  
176 - .opacity(0.8)  
177 - .width("100%")  
178 - .justifyContent(FlexAlign.SpaceAround) 114 + this.videoComp()
179 } 115 }
180 .width(this.positionWidth) 116 .width(this.positionWidth)
181 .height(this.positionHeight) 117 .height(this.positionHeight)
  118 + .backgroundColor(Color.Red)
182 .alignRules({ 119 .alignRules({
183 top: { anchor: "__container__", align: VerticalAlign.Top }, 120 top: { anchor: "__container__", align: VerticalAlign.Top },
184 }) 121 })
@@ -230,6 +167,7 @@ export struct WdWebLocalComponent { @@ -230,6 +167,7 @@ export struct WdWebLocalComponent {
230 this.positionLeft = Number(data?.data?.positionLeft) || 0 167 this.positionLeft = Number(data?.data?.positionLeft) || 0
231 this.positionTop = Number(data?.data?.positionTop) || 0 168 this.positionTop = Number(data?.data?.positionTop) || 0
232 this.videoLandscape = data?.data?.videoLandscape || '1' 169 this.videoLandscape = data?.data?.videoLandscape || '1'
  170 + this.controller.start()
233 } 171 }
234 } 172 }
235 /** 173 /**
@@ -262,5 +200,95 @@ export struct WdWebLocalComponent { @@ -262,5 +200,95 @@ export struct WdWebLocalComponent {
262 this.webviewControl.refresh() 200 this.webviewControl.refresh()
263 } 201 }
264 } 202 }
  203 +
  204 + @Builder
  205 + videoComp(){
  206 + Video({
  207 + src: this.videoUrl,
  208 + currentProgressRate: this.curRate,
  209 + controller: this.controller
  210 + })
  211 + .width(this.positionWidth)
  212 + .height(this.positionHeight)
  213 + .borderRadius(5)
  214 + .controls(this.isFullScreen?true:false)
  215 + .autoPlay(true)
  216 + .objectFit(ImageFit.Contain)
  217 + .onStart(() => {
  218 + this.isPause = false
  219 + })
  220 + .onPause(() => {
  221 + this.isPause = true
  222 + })
  223 + .onPrepared((event) => {
  224 + if (event) {
  225 + this.durationTime = event.duration
  226 + }
  227 + })
  228 + .onUpdate((event) => {
  229 + if (event) {
  230 + this.currentTime = event.time
  231 + }
  232 + })
  233 + .onFullscreenChange((fullscreen)=>{
  234 + this.isFullScreen = fullscreen.fullscreen
  235 + if (this.isFullScreen) {
  236 + WindowModel.shared.setPreferredOrientation(this.videoLandscape == '2' ?
  237 + window.Orientation.PORTRAIT :
  238 + window.Orientation.LANDSCAPE)
  239 + }else {
  240 + WindowModel.shared.setPreferredOrientation(window.Orientation.PORTRAIT)
  241 + }
  242 + })
  243 + Row() {
  244 + Image(this.isPause ? $r('app.media.icon_play') : $r('app.media.icon_pause'))
  245 + .width(24)
  246 + .height(24)
  247 + .onClick(() => {
  248 + if (this.isPause) {
  249 + this.controller.start()
  250 + } else {
  251 + this.controller.pause()
  252 + }
  253 + })
  254 + Row() {
  255 + Text(DateTimeUtils.getFormattedDuration(this.currentTime * 1000))
  256 + .fontSize(12)
  257 + .fontColor(Color.White)
  258 + .fontWeight(600)
  259 + Slider({
  260 + value: this.currentTime,
  261 + min: 0,
  262 + max: this.durationTime
  263 + })
  264 + .width("50%")
  265 + .selectedColor('#ED2800')
  266 + .margin({ left: 4, right: 4 })// .blockStyle({
  267 + // type: SliderBlockType.IMAGE,
  268 + // image: $r('app.media.slider_block')
  269 + // })
  270 + // .blockSize({ width: 18, height: 12 })
  271 + .onChange((value: number, mode: SliderChangeMode) => {
  272 + this.controller.setCurrentTime(value);
  273 + })
  274 + Text(DateTimeUtils.getFormattedDuration(this.durationTime * 1000))
  275 + .fontSize(12)
  276 + .fontColor(Color.White)
  277 + .fontWeight(600)
  278 + }
  279 + .justifyContent(FlexAlign.Center)
  280 +
  281 + // Image($r('app.media.icon_full_screen'))
  282 + // .width(24)
  283 + // .height(24)
  284 + // .onClick(() => {
  285 + // this.controller.requestFullscreen(true)
  286 + // })
  287 + }
  288 + .opacity(0.8)
  289 + .width("100%")
  290 + .justifyContent(FlexAlign.SpaceAround)
  291 + }
  292 +
265 } 293 }
266 294