王士厅

fix: 在热点频道进入稿件详情后,点击下方的语音播放按钮后,退出稿件详情在进入后,语音播放按钮处缺少动效

@@ -31,6 +31,11 @@ import DailyPaperTopicModel from '../../model/DailyPaperTopicModel'; @@ -31,6 +31,11 @@ import DailyPaperTopicModel from '../../model/DailyPaperTopicModel';
31 31
32 const TAG = 'MorningEveningPaperComponent'; 32 const TAG = 'MorningEveningPaperComponent';
33 33
  34 +interface newsInfo {
  35 + currentStatus: number | string | undefined,
  36 + url: string
  37 +}
  38 +
34 @Entry 39 @Entry
35 @Component 40 @Component
36 export struct MorningEveningPaperComponent { 41 export struct MorningEveningPaperComponent {
@@ -138,6 +143,10 @@ export struct MorningEveningPaperComponent { @@ -138,6 +143,10 @@ export struct MorningEveningPaperComponent {
138 this.fetchData() 143 this.fetchData()
139 } 144 }
140 } 145 }
  146 + EmitterUtils.receiveEvent(EmitterEventId.AUDIO_CHANGE_STATUS, (val: number | string | undefined) => {
  147 + // console.log(TAG, 'this.currentStatus', val)
  148 + this.currentStatus = val
  149 + })
141 } 150 }
142 151
143 async fetchData() { 152 async fetchData() {
@@ -191,6 +200,25 @@ export struct MorningEveningPaperComponent { @@ -191,6 +200,25 @@ export struct MorningEveningPaperComponent {
191 this.audioPlayUrl = compInfoBean?.compList[0].audioDataList[0]?.audioUrl 200 this.audioPlayUrl = compInfoBean?.compList[0].audioDataList[0]?.audioUrl
192 this.audioTitle = compInfoBean?.compList[0].audioDataList[0]?.title 201 this.audioTitle = compInfoBean?.compList[0].audioDataList[0]?.title
193 // console.log(TAG, 'this.audioPlayUrl', this.audioPlayUrl) 202 // console.log(TAG, 'this.audioPlayUrl', this.audioPlayUrl)
  203 + const newsInfo = this.AudioSuspension.newsInfo();
  204 + // console.log(TAG, 'newsInfo', newsInfo)
  205 + if (newsInfo) {
  206 + try {
  207 + const parsedInfo: newsInfo = JSON.parse(newsInfo);
  208 + const url = parsedInfo.url;
  209 +
  210 + // console.log(TAG, 'url', url)
  211 + // console.log(TAG, 'this.audioUrl', this.audioUrl)
  212 +
  213 + if (url == this.audioPlayUrl) {
  214 + this.currentStatus = parsedInfo.currentStatus
  215 + }
  216 + } catch (error) {
  217 + console.error(`${TAG} Error parsing newsInfo:`, error);
  218 + }
  219 + } else {
  220 + console.log(`${TAG} No newsInfo available`);
  221 + }
194 } 222 }
195 } 223 }
196 224
@@ -41,6 +41,11 @@ const TAG = 'OperRowListView'; @@ -41,6 +41,11 @@ const TAG = 'OperRowListView';
41 }) 41 })
42 */ 42 */
43 43
  44 +interface newsInfo {
  45 + currentStatus: number | string | undefined,
  46 + url: string
  47 +}
  48 +
44 @Preview 49 @Preview
45 @Component 50 @Component
46 export struct OperRowListView { 51 export struct OperRowListView {
@@ -103,6 +108,7 @@ export struct OperRowListView { @@ -103,6 +108,7 @@ export struct OperRowListView {
103 // console.info(TAG, 'this.needLike', this.needLike) 108 // console.info(TAG, 'this.needLike', this.needLike)
104 this.handleStyle() 109 this.handleStyle()
105 this.onDetailUpdated() 110 this.onDetailUpdated()
  111 +
106 EmitterUtils.receiveEvent(EmitterEventId.AUDIO_CHANGE_STATUS, (val: number | string | undefined) => { 112 EmitterUtils.receiveEvent(EmitterEventId.AUDIO_CHANGE_STATUS, (val: number | string | undefined) => {
107 // console.log(TAG, 'this.currentStatus', val) 113 // console.log(TAG, 'this.currentStatus', val)
108 this.currentStatus = val 114 this.currentStatus = val
@@ -187,6 +193,25 @@ export struct OperRowListView { @@ -187,6 +193,25 @@ export struct OperRowListView {
187 this.audioTitle = this.contentDetailData.newsTitle || '' 193 this.audioTitle = this.contentDetailData.newsTitle || ''
188 // console.log(TAG, 'this.audioUrl+++', this.audioUrl) 194 // console.log(TAG, 'this.audioUrl+++', this.audioUrl)
189 // console.log(TAG, 'this.audioTitle+++', this.audioTitle) 195 // console.log(TAG, 'this.audioTitle+++', this.audioTitle)
  196 + const newsInfo = this.AudioSuspension.newsInfo();
  197 + // console.log(TAG, 'newsInfo', newsInfo)
  198 + if (newsInfo) {
  199 + try {
  200 + const parsedInfo: newsInfo = JSON.parse(newsInfo);
  201 + const url = parsedInfo.url;
  202 +
  203 + // console.log(TAG, 'url', url)
  204 + // console.log(TAG, 'this.audioUrl', this.audioUrl)
  205 +
  206 + if (url == this.audioUrl) {
  207 + this.currentStatus = parsedInfo.currentStatus
  208 + }
  209 + } catch (error) {
  210 + console.error(`${TAG} Error parsing newsInfo:`, error);
  211 + }
  212 + } else {
  213 + console.log(`${TAG} No newsInfo available`);
  214 + }
190 } 215 }
191 // 2:竖屏直播页 3:图集 4:横屏直播页 216 // 2:竖屏直播页 3:图集 4:横屏直播页
192 if(this.pageComponentType == 2 || this.pageComponentType == 4) { 217 if(this.pageComponentType == 2 || this.pageComponentType == 4) {
@@ -475,10 +500,10 @@ export struct OperRowListView { @@ -475,10 +500,10 @@ export struct OperRowListView {
475 } 500 }
476 ] 501 ]
477 } 502 }
478 - console.info(TAG, '查询用户对作品收藏1', JSON.stringify(params)) 503 + // console.info(TAG, '查询用户对作品收藏1', JSON.stringify(params))
479 // console.info(TAG, '查询用户对作品收藏11', JSON.stringify(params)) 504 // console.info(TAG, '查询用户对作品收藏11', JSON.stringify(params))
480 let data = await MultiPictureDetailViewModel.getInteractDataStatus(params) 505 let data = await MultiPictureDetailViewModel.getInteractDataStatus(params)
481 - console.info(TAG, '查询用户对作品收藏22', JSON.stringify(data)) 506 + // console.info(TAG, '查询用户对作品收藏22', JSON.stringify(data))
482 this.newsStatusOfUser = data[0]; 507 this.newsStatusOfUser = data[0];
483 } catch (exception) { 508 } catch (exception) {
484 // console.error(TAG, JSON.stringify(exception)) 509 // console.error(TAG, JSON.stringify(exception))
@@ -491,9 +516,9 @@ export struct OperRowListView { @@ -491,9 +516,9 @@ export struct OperRowListView {
491 async toggleCollectStatus() { 516 async toggleCollectStatus() {
492 // 未登录,跳转登录 517 // 未登录,跳转登录
493 const user_id = await SPHelper.default.get(SpConstants.USER_ID, '') 518 const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
494 - console.log(TAG, '收藏点击,登录', user_id) 519 + // console.log(TAG, '收藏点击,登录', user_id)
495 if (!user_id) { 520 if (!user_id) {
496 - console.log(TAG, '收藏点击,用户未登录') 521 + // console.log(TAG, '收藏点击,用户未登录')
497 if (this.dialogBeforeJumpOtherPageAction) { this.dialogBeforeJumpOtherPageAction() } 522 if (this.dialogBeforeJumpOtherPageAction) { this.dialogBeforeJumpOtherPageAction() }
498 WDRouterRule.jumpWithPage(WDRouterPage.loginPage) 523 WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
499 return 524 return
@@ -524,7 +549,7 @@ export struct OperRowListView { @@ -524,7 +549,7 @@ export struct OperRowListView {
524 } 549 }
525 } 550 }
526 551
527 - console.log(TAG, '收藏点击', JSON.stringify(params)) 552 + // console.log(TAG, '收藏点击', JSON.stringify(params))
528 PageRepository.postExecuteCollectRecord(params).then(res => { 553 PageRepository.postExecuteCollectRecord(params).then(res => {
529 if (this.newsStatusOfUser && res.code == 0) { 554 if (this.newsStatusOfUser && res.code == 0) {
530 this.newsStatusOfUser.collectStatus = this.newsStatusOfUser?.collectStatus === 1 ? 0 : 1 555 this.newsStatusOfUser.collectStatus = this.newsStatusOfUser?.collectStatus === 1 ? 0 : 1
@@ -536,7 +561,7 @@ export struct OperRowListView { @@ -536,7 +561,7 @@ export struct OperRowListView {
536 } 561 }
537 this.queryContentInteractCount() 562 this.queryContentInteractCount()
538 } 563 }
539 - console.log(TAG, '收藏点击 this.newsStatusOfUser', JSON.stringify(this.newsStatusOfUser)) 564 + // console.log(TAG, '收藏点击 this.newsStatusOfUser', JSON.stringify(this.newsStatusOfUser))
540 }).catch((error:Error) =>{ 565 }).catch((error:Error) =>{
541 ToastUtils.showToast(error.message, 1000); 566 ToastUtils.showToast(error.message, 1000);
542 }) 567 })
@@ -553,9 +578,9 @@ export struct OperRowListView { @@ -553,9 +578,9 @@ export struct OperRowListView {
553 contentType: this.contentDetailData?.newsType, 578 contentType: this.contentDetailData?.newsType,
554 }] 579 }]
555 } 580 }
556 - console.log(TAG, '查询点赞、收藏数量', JSON.stringify(params)) 581 + // console.log(TAG, '查询点赞、收藏数量', JSON.stringify(params))
557 PageRepository.getContentInteract(params).then(res => { 582 PageRepository.getContentInteract(params).then(res => {
558 - console.log(TAG, '查询点赞、收藏数量 res', JSON.stringify(res)) 583 + // console.log(TAG, '查询点赞、收藏数量 res', JSON.stringify(res))
559 if (res.data) { 584 if (res.data) {
560 this.interactData.likeNum = NumberFormatterUtils.formatNumberWithWan(res.data[0]?.likeNum) 585 this.interactData.likeNum = NumberFormatterUtils.formatNumberWithWan(res.data[0]?.likeNum)
561 this.interactData.collectNum = NumberFormatterUtils.formatNumberWithWan(res.data[0]?.collectNum) 586 this.interactData.collectNum = NumberFormatterUtils.formatNumberWithWan(res.data[0]?.collectNum)
@@ -13,7 +13,6 @@ export class AudioSuspensionModel { @@ -13,7 +13,6 @@ export class AudioSuspensionModel {
13 public playerController: SubscribedAbstractProperty<WDPlayerController> = AppStorage.link<WDPlayerController>('playerController') 13 public playerController: SubscribedAbstractProperty<WDPlayerController> = AppStorage.link<WDPlayerController>('playerController')
14 public floatWindowClass: SubscribedAbstractProperty<window.Window> = AppStorage.link<window.Window>('floatWindowClass') 14 public floatWindowClass: SubscribedAbstractProperty<window.Window> = AppStorage.link<window.Window>('floatWindowClass')
15 public srcTitle: string = '' 15 public srcTitle: string = ''
16 - private url: string = ''  
17 // 窗口是否最小化 16 // 窗口是否最小化
18 private isMinimize: SubscribedAbstractProperty<boolean> = AppStorage.link<boolean>('isMinimize') 17 private isMinimize: SubscribedAbstractProperty<boolean> = AppStorage.link<boolean>('isMinimize')
19 constructor() { 18 constructor() {
@@ -40,8 +39,7 @@ export class AudioSuspensionModel { @@ -40,8 +39,7 @@ export class AudioSuspensionModel {
40 * 配置音频地址 39 * 配置音频地址
41 */ 40 */
42 public async setPlayerUrl(url: string, srcTitle: string, srcContentId?: string, srcSource?: string) { 41 public async setPlayerUrl(url: string, srcTitle: string, srcContentId?: string, srcSource?: string) {
43 - /*console.log(TAG,'this.url', this.url)  
44 - console.log(TAG,'url', url)*/ 42 + // console.log(TAG,'url', url)
45 this.playerController.get().keepOnBackground = true 43 this.playerController.get().keepOnBackground = true
46 BackgroundAudioController.sharedController().avplayerController = this.playerController.get() 44 BackgroundAudioController.sharedController().avplayerController = this.playerController.get()
47 await BackgroundAudioController.sharedController().createSession() 45 await BackgroundAudioController.sharedController().createSession()
@@ -50,7 +48,7 @@ export class AudioSuspensionModel { @@ -50,7 +48,7 @@ export class AudioSuspensionModel {
50 await BackgroundAudioController.sharedController().setSessionMetaData(srcContentId ?? "", srcTitle, $r("app.media.system_audio_icon_bk_center"), srcSource ?? "") 48 await BackgroundAudioController.sharedController().setSessionMetaData(srcContentId ?? "", srcTitle, $r("app.media.system_audio_icon_bk_center"), srcSource ?? "")
51 BackgroundAudioController.sharedController().stopUseFeatures() 49 BackgroundAudioController.sharedController().stopUseFeatures()
52 50
53 - if (this.url === url) { 51 + if (this.playerController.get().getUrl() === url) {
54 this.isMinimize = AppStorage.link<boolean>('isMinimize') 52 this.isMinimize = AppStorage.link<boolean>('isMinimize')
55 // console.log(TAG, 'this.isMinimize', this.isMinimize?.get()) 53 // console.log(TAG, 'this.isMinimize', this.isMinimize?.get())
56 if (this.isMinimize?.get()) { 54 if (this.isMinimize?.get()) {
@@ -61,7 +59,6 @@ export class AudioSuspensionModel { @@ -61,7 +59,6 @@ export class AudioSuspensionModel {
61 this.playerController.get().switchPlayOrPause() 59 this.playerController.get().switchPlayOrPause()
62 } 60 }
63 } else { 61 } else {
64 - this.url = url  
65 this.playerController.get().firstPlay(url) 62 this.playerController.get().firstPlay(url)
66 this.playerController.get().onCanplay = () => { 63 this.playerController.get().onCanplay = () => {
67 this.playerController.get().play() 64 this.playerController.get().play()
@@ -120,6 +117,16 @@ export class AudioSuspensionModel { @@ -120,6 +117,16 @@ export class AudioSuspensionModel {
120 // console.info(TAG, 'Succeeded in minimizing the window.'); 117 // console.info(TAG, 'Succeeded in minimizing the window.');
121 }); 118 });
122 } 119 }
  120 + // 获取当前播放状态 newsId作为参数
  121 + public newsInfo() {
  122 + const currentStatus = this.playerController.get().getStatus()
  123 + const url = this.playerController.get().getUrl()
  124 + return JSON.stringify({ currentStatus, url })
  125 + }
  126 +
  127 + public switchPlayOrPause() {
  128 + this.playerController.get().switchPlayOrPause()
  129 + }
123 130
124 131
125 132
@@ -430,6 +430,10 @@ export class WDPlayerController { @@ -430,6 +430,10 @@ export class WDPlayerController {
430 return this.status; 430 return this.status;
431 } 431 }
432 432
  433 + getUrl() {
  434 + return this.url
  435 + }
  436 +
433 getPlayer() { 437 getPlayer() {
434 return this.avPlayer; 438 return this.avPlayer;
435 } 439 }