王士厅

音频悬浮窗问题

@@ -27,6 +27,7 @@ import TrackingPageBrowseUtils from '../../utils/TrackingPageBrowseUtils' @@ -27,6 +27,7 @@ import TrackingPageBrowseUtils from '../../utils/TrackingPageBrowseUtils'
27 import {TrackConstants,TrackParamConvert}from 'wdTracking/Index' 27 import {TrackConstants,TrackParamConvert}from 'wdTracking/Index'
28 import { ColorUtils } from '../../utils/ColorUtils'; 28 import { ColorUtils } from '../../utils/ColorUtils';
29 import { EmptyComponent,WDViewDefaultType } from '../view/EmptyComponent'; 29 import { EmptyComponent,WDViewDefaultType } from '../view/EmptyComponent';
  30 +import { EmitterEventId, EmitterUtils } from 'wdKit/Index'
30 31
31 const TAG = 'MorningEveningPaperComponent'; 32 const TAG = 'MorningEveningPaperComponent';
32 33
@@ -71,6 +72,7 @@ export struct MorningEveningPaperComponent { @@ -71,6 +72,7 @@ export struct MorningEveningPaperComponent {
71 @State bottomSafeHeight: number = 0; 72 @State bottomSafeHeight: number = 0;
72 @State isHasTopView: boolean = false; 73 @State isHasTopView: boolean = false;
73 @State scrollOffset: number = 0 74 @State scrollOffset: number = 0
  75 + @State currentStatus: number | string |undefined = 0;
74 76
75 private audioDataList: AudioDataList[] = [] 77 private audioDataList: AudioDataList[] = []
76 private playerController: WDPlayerController = new WDPlayerController(); 78 private playerController: WDPlayerController = new WDPlayerController();
@@ -182,6 +184,10 @@ export struct MorningEveningPaperComponent { @@ -182,6 +184,10 @@ export struct MorningEveningPaperComponent {
182 184
183 } 185 }
184 186
  187 + EmitterUtils.receiveEvent(EmitterEventId.AUDIO_CHANGE_STATUS, (val: number | string | undefined) => {
  188 + this.currentStatus = val
  189 + })
  190 +
185 } 191 }
186 192
187 // 批量查询内容当前用户点赞、收藏状态评论个数 193 // 批量查询内容当前用户点赞、收藏状态评论个数
@@ -338,7 +344,7 @@ export struct MorningEveningPaperComponent { @@ -338,7 +344,7 @@ export struct MorningEveningPaperComponent {
338 .height('100%') 344 .height('100%')
339 .objectFit(ImageFit.Contain) 345 .objectFit(ImageFit.Contain)
340 346
341 - Image($r('app.media.ic_red_triangle')) 347 + Image(this.currentStatus === PlayerConstants.STATUS_START ? $r("app.media.icon_audio_pause") : $r("app.media.icon_audio_playing"))
342 .width(24) 348 .width(24)
343 .height(24) 349 .height(24)
344 .margin({ left: 10 })// .alignSelf(ItemAlign.Center) 350 .margin({ left: 10 })// .alignSelf(ItemAlign.Center)
@@ -16,6 +16,7 @@ export class AudioSuspensionModel { @@ -16,6 +16,7 @@ export class AudioSuspensionModel {
16 private url: string = '' 16 private url: string = ''
17 private expandWidth: number = vp2px(243) 17 private expandWidth: number = vp2px(243)
18 private expandHeight: number = vp2px(60) 18 private expandHeight: number = vp2px(60)
  19 + private initMoveX = vp2px(12)
19 // 窗口是否最小化 20 // 窗口是否最小化
20 private isMinimize: SubscribedAbstractProperty<boolean> = AppStorage.link<boolean>('isMinimize') 21 private isMinimize: SubscribedAbstractProperty<boolean> = AppStorage.link<boolean>('isMinimize')
21 constructor() { 22 constructor() {
@@ -27,7 +28,7 @@ export class AudioSuspensionModel { @@ -27,7 +28,7 @@ export class AudioSuspensionModel {
27 private initPlayerController() { 28 private initPlayerController() {
28 if(this.playerController === undefined) { 29 if(this.playerController === undefined) {
29 Logger.info(TAG, 'playerController undefined') 30 Logger.info(TAG, 'playerController undefined')
30 - AppStorage.setOrCreate('playerController', new WDPlayerController()); 31 + AppStorage.setOrCreate('playerController', new WDPlayerController({loop: false}));
31 this.playerController = AppStorage.link<WDPlayerController>('playerController') 32 this.playerController = AppStorage.link<WDPlayerController>('playerController')
32 Logger.info(TAG, 'playerController create success') 33 Logger.info(TAG, 'playerController create success')
33 this.playerController.get().onStatusChange = (status: number) => { 34 this.playerController.get().onStatusChange = (status: number) => {
@@ -42,8 +43,8 @@ export class AudioSuspensionModel { @@ -42,8 +43,8 @@ export class AudioSuspensionModel {
42 * 配置音频地址 43 * 配置音频地址
43 */ 44 */
44 public setPlayerUrl(url: string, srcTitle: string) { 45 public setPlayerUrl(url: string, srcTitle: string) {
45 - // console.log(TAG,'this.url', this.url)  
46 - // console.log(TAG,'url', url) 46 + /*console.log(TAG,'this.url', this.url)
  47 + console.log(TAG,'url', url)*/
47 if (this.url === url) { 48 if (this.url === url) {
48 this.isMinimize = AppStorage.link<boolean>('isMinimize') 49 this.isMinimize = AppStorage.link<boolean>('isMinimize')
49 console.log(TAG, 'this.isMinimize', this.isMinimize?.get()) 50 console.log(TAG, 'this.isMinimize', this.isMinimize?.get())
@@ -60,7 +61,7 @@ export class AudioSuspensionModel { @@ -60,7 +61,7 @@ export class AudioSuspensionModel {
60 } 61 }
61 this.srcTitle = srcTitle 62 this.srcTitle = srcTitle
62 EmitterUtils.sendEvent(EmitterEventId.AUDIO_CHANGE_TITLe, this.srcTitle) 63 EmitterUtils.sendEvent(EmitterEventId.AUDIO_CHANGE_TITLe, this.srcTitle)
63 - this.resizeWindow(this.expandWidth, this.expandHeight) 64 + EmitterUtils.sendEvent(EmitterEventId.AUDIO_WINDOW_EXPAND, 1)
64 } 65 }
65 this.showWindow() 66 this.showWindow()
66 } 67 }
@@ -99,9 +100,8 @@ export class AudioSuspensionModel { @@ -99,9 +100,8 @@ export class AudioSuspensionModel {
99 console.info(TAG, 'floatWindowClass Succeeded in changing the window size.'); 100 console.info(TAG, 'floatWindowClass Succeeded in changing the window size.');
100 }); 101 });
101 } 102 }
102 -  
103 public moveWindow(y: number) { 103 public moveWindow(y: number) {
104 - this.floatWindowClass.get().moveWindowTo(0, vp2px(y), (err: BusinessError) => { 104 + this.floatWindowClass.get().moveWindowTo(this.initMoveX, vp2px(y), (err: BusinessError) => {
105 let errCode: number = err.code; 105 let errCode: number = err.code;
106 if (errCode) { 106 if (errCode) {
107 console.error('floatWindowClass Failed to move the window. Cause:' + JSON.stringify(err)); 107 console.error('floatWindowClass Failed to move the window. Cause:' + JSON.stringify(err));
@@ -7,13 +7,17 @@ import { TrackingPlay } from 'wdTracking/Index'; @@ -7,13 +7,17 @@ import { TrackingPlay } from 'wdTracking/Index';
7 import { ParamType } from 'wdTracking/Index'; 7 import { ParamType } from 'wdTracking/Index';
8 import { DateTimeUtils } from 'wdKit/Index'; 8 import { DateTimeUtils } from 'wdKit/Index';
9 9
  10 +interface obj {
  11 + loop: boolean
  12 +}
  13 +
10 @Observed 14 @Observed
11 export class WDPlayerController { 15 export class WDPlayerController {
12 private initPromise: Promise<void>; 16 private initPromise: Promise<void>;
13 private avPlayer?: media.AVPlayer; 17 private avPlayer?: media.AVPlayer;
14 private duration: number = 0; 18 private duration: number = 0;
15 private status: number = PlayerConstants.STATUS_IDLE; 19 private status: number = PlayerConstants.STATUS_IDLE;
16 - private loop: boolean = false; 20 + private loop: boolean = true;
17 private url: string = ''; 21 private url: string = '';
18 private surfaceId: string = ''; // 若播放音频,无需设置surfaceId 22 private surfaceId: string = ''; // 若播放音频,无需设置surfaceId
19 private playSpeed: number = 1; 23 private playSpeed: number = 1;
@@ -41,9 +45,12 @@ export class WDPlayerController { @@ -41,9 +45,12 @@ export class WDPlayerController {
41 45
42 46
43 47
44 - constructor() { 48 + constructor(obj?: obj) {
45 Logger.error("初始化") 49 Logger.error("初始化")
46 this.initPromise = this.createAVPlayer(); 50 this.initPromise = this.createAVPlayer();
  51 + if(obj?.loop === false) {
  52 + this.loop = false
  53 + }
47 } 54 }
48 55
49 /** 56 /**
@@ -103,6 +110,7 @@ export class WDPlayerController { @@ -103,6 +110,7 @@ export class WDPlayerController {
103 if (this.onCanplay) { 110 if (this.onCanplay) {
104 this.onCanplay() 111 this.onCanplay()
105 } 112 }
  113 + this.avPlayer.loop = this.loop
106 break; 114 break;
107 case AVPlayerStatus.PLAYING: 115 case AVPlayerStatus.PLAYING:
108 if(this.onLoaded) { 116 if(this.onLoaded) {
@@ -122,10 +130,14 @@ export class WDPlayerController { @@ -122,10 +130,14 @@ export class WDPlayerController {
122 if (this.continue) { 130 if (this.continue) {
123 this.continue(); 131 this.continue();
124 } else { 132 } else {
  133 + if(this.loop) {
125 this.duration = 0; 134 this.duration = 0;
126 this.url = this.avPlayer.url || ''; 135 this.url = this.avPlayer.url || '';
127 this.avPlayer.reset(); 136 this.avPlayer.reset();
128 } 137 }
  138 + this.status = PlayerConstants.STATUS_COMPLETION;
  139 + this.watchStatus();
  140 + }
129 break; 141 break;
130 case AVPlayerStatus.RELEASED: 142 case AVPlayerStatus.RELEASED:
131 this.avPlayer.release(); 143 this.avPlayer.release();
@@ -396,7 +408,7 @@ export class WDPlayerController { @@ -396,7 +408,7 @@ export class WDPlayerController {
396 408
397 watchStatus() { 409 watchStatus() {
398 console.log('watchStatus', this.status) 410 console.log('watchStatus', this.status)
399 - if(this.status == 1){ 411 + if(this.status == PlayerConstants.STATUS_START){
400 console.log('播放视频') 412 console.log('播放视频')
401 console.log('播放视频prepareTime',JSON.stringify(this.prepareTime)) 413 console.log('播放视频prepareTime',JSON.stringify(this.prepareTime))
402 console.log('播放视频pageName',JSON.stringify(this.pageName)) 414 console.log('播放视频pageName',JSON.stringify(this.pageName))
@@ -404,7 +416,7 @@ export class WDPlayerController { @@ -404,7 +416,7 @@ export class WDPlayerController {
404 // 播放埋点 416 // 播放埋点
405 TrackingPlay.videoPositivePlay(Number(this.prepareTime),this.pageName, this.pageName, this.pageParam) 417 TrackingPlay.videoPositivePlay(Number(this.prepareTime),this.pageName, this.pageName, this.pageParam)
406 } 418 }
407 - if(this.status == 2){ 419 + if(this.status == PlayerConstants.STATUS_COMPLETION){
408 let initDuration = Math.floor(Number(this.duration)/1000) 420 let initDuration = Math.floor(Number(this.duration)/1000)
409 console.log('播放结束') 421 console.log('播放结束')
410 console.log('播放结束currentPlayTime',JSON.stringify(this.currentPlayTime)) 422 console.log('播放结束currentPlayTime',JSON.stringify(this.currentPlayTime))
@@ -57,8 +57,9 @@ export default class EntryAbility extends UIAbility { @@ -57,8 +57,9 @@ export default class EntryAbility extends UIAbility {
57 AppStorage.setOrCreate('topSafeHeight', topSafeHeight); 57 AppStorage.setOrCreate('topSafeHeight', topSafeHeight);
58 AppStorage.setOrCreate('windowWidth', width); 58 AppStorage.setOrCreate('windowWidth', width);
59 AppStorage.setOrCreate('windowHeight', height); 59 AppStorage.setOrCreate('windowHeight', height);
60 - // 音频悬浮窗初始移动位置604为ui高度  
61 - let initMoveY = vp2px(604) 60 + // 音频悬浮窗初始移动位置604为ui高度, 下面的初始位置根据mate60 pro手动调整
  61 + let initMoveY = vp2px(576)
  62 + let initMoveX = vp2px(12)
62 63
63 this.onWindowSetup(windowClass) 64 this.onWindowSetup(windowClass)
64 65
@@ -81,7 +82,7 @@ export default class EntryAbility extends UIAbility { @@ -81,7 +82,7 @@ export default class EntryAbility extends UIAbility {
81 floatWindowClass = data; 82 floatWindowClass = data;
82 AppStorage.setOrCreate('floatWindowClass', floatWindowClass); 83 AppStorage.setOrCreate('floatWindowClass', floatWindowClass);
83 // 2.悬浮窗窗口创建成功后,设置悬浮窗的位置、大小及相关属性等。 84 // 2.悬浮窗窗口创建成功后,设置悬浮窗的位置、大小及相关属性等。
84 - floatWindowClass.moveWindowTo(0, initMoveY, (err: BusinessError) => { 85 + floatWindowClass.moveWindowTo(initMoveX, initMoveY, (err: BusinessError) => {
85 let errCode: number = err.code; 86 let errCode: number = err.code;
86 if (errCode) { 87 if (errCode) {
87 Logger.error('floatWindowClass Failed to move the window. Cause:' + JSON.stringify(err)); 88 Logger.error('floatWindowClass Failed to move the window. Cause:' + JSON.stringify(err));
@@ -40,11 +40,11 @@ struct Index { @@ -40,11 +40,11 @@ struct Index {
40 40
41 EmitterUtils.receiveEvent(EmitterEventId.AUDIO_CHANGE_STATUS, (val: number | string | undefined) => { 41 EmitterUtils.receiveEvent(EmitterEventId.AUDIO_CHANGE_STATUS, (val: number | string | undefined) => {
42 // val 2 pause 42 // val 2 pause
43 - if(val === 2) {  
44 - console.log(TAG,'this.currentStatus 2 ', val) 43 + if(val === PlayerConstants.STATUS_PAUSE || val === PlayerConstants.STATUS_COMPLETION) {
  44 + console.log(TAG,'AUDIO_CHANGE_STATUS this.currentStatus 2 ', val)
45 lottie.pause(this.name) 45 lottie.pause(this.name)
46 - } else if(val === 1) {  
47 - console.log(TAG,'this.currentStatus 1 ', val) 46 + } else if(val === PlayerConstants.STATUS_START) {
  47 + console.log(TAG,'AUDIO_CHANGE_STATUS this.currentStatus 1 ', val)
48 lottie.play(this.name) 48 lottie.play(this.name)
49 } 49 }
50 this.currentStatus = val 50 this.currentStatus = val
@@ -76,7 +76,7 @@ struct Index { @@ -76,7 +76,7 @@ struct Index {
76 76
77 build() { 77 build() {
78 Stack({ alignContent: Alignment.End }) { 78 Stack({ alignContent: Alignment.End }) {
79 - if(this.isExpand) { 79 + Stack({ alignContent: Alignment.End }) {
80 Column() { //标题 时间 进度条 80 Column() { //标题 时间 进度条
81 Marquee({ 81 Marquee({
82 start: true, 82 start: true,
@@ -156,7 +156,9 @@ struct Index { @@ -156,7 +156,9 @@ struct Index {
156 } 156 }
157 .width(80) 157 .width(80)
158 .height(60) 158 .height(60)
159 - } else { 159 + }
  160 + .visibility(this.isExpand ? Visibility.Visible : Visibility.Hidden)
  161 +
160 Row() { 162 Row() {
161 LottieView({ 163 LottieView({
162 name: this.name, 164 name: this.name,
@@ -170,7 +172,7 @@ struct Index { @@ -170,7 +172,7 @@ struct Index {
170 .justifyContent(FlexAlign.Center) 172 .justifyContent(FlexAlign.Center)
171 .width(60) 173 .width(60)
172 .height(60) 174 .height(60)
173 - } 175 + .visibility(!this.isExpand ? Visibility.Visible : Visibility.Hidden)
174 } 176 }
175 .parallelGesture( 177 .parallelGesture(
176 GestureGroup(GestureMode.Parallel, 178 GestureGroup(GestureMode.Parallel,