Showing
10 changed files
with
106 additions
and
76 deletions
| @@ -13,6 +13,7 @@ import { image } from '@kit.ImageKit'; | @@ -13,6 +13,7 @@ import { image } from '@kit.ImageKit'; | ||
| 13 | import { getPicture, imageNet2PixelMap } from '../../utils/ImageUtils'; | 13 | import { getPicture, imageNet2PixelMap } from '../../utils/ImageUtils'; |
| 14 | import { effectKit } from '@kit.ArkGraphics2D'; | 14 | import { effectKit } from '@kit.ArkGraphics2D'; |
| 15 | import { window } from '@kit.ArkUI'; | 15 | import { window } from '@kit.ArkUI'; |
| 16 | +import { AudioSuspensionModel } from '../../viewmodel/AudioSuspensionModel' | ||
| 16 | 17 | ||
| 17 | const TAG = 'MorningEveningPaperComponent'; | 18 | const TAG = 'MorningEveningPaperComponent'; |
| 18 | 19 | ||
| @@ -54,6 +55,8 @@ export struct MorningEveningPaperComponent { | @@ -54,6 +55,8 @@ export struct MorningEveningPaperComponent { | ||
| 54 | @State topSafeHeight: number = 0; | 55 | @State topSafeHeight: number = 0; |
| 55 | private audioDataList: AudioDataList[] = [] | 56 | private audioDataList: AudioDataList[] = [] |
| 56 | private playerController: WDPlayerController = new WDPlayerController(); | 57 | private playerController: WDPlayerController = new WDPlayerController(); |
| 58 | + private AudioSuspension = new AudioSuspensionModel() | ||
| 59 | + | ||
| 57 | simpleAudioDialog: CustomDialogController = new CustomDialogController({ | 60 | simpleAudioDialog: CustomDialogController = new CustomDialogController({ |
| 58 | builder: PaperReaderSimpleDialog({ | 61 | builder: PaperReaderSimpleDialog({ |
| 59 | cancel: this.onCancel, | 62 | cancel: this.onCancel, |
| @@ -261,8 +264,9 @@ export struct MorningEveningPaperComponent { | @@ -261,8 +264,9 @@ export struct MorningEveningPaperComponent { | ||
| 261 | .objectFit(ImageFit.Contain) | 264 | .objectFit(ImageFit.Contain) |
| 262 | .onClick(() => { | 265 | .onClick(() => { |
| 263 | Logger.info("TAG", "cj compInfoBean onClick1 = " + this.isAudioPlaying) | 266 | Logger.info("TAG", "cj compInfoBean onClick1 = " + this.isAudioPlaying) |
| 264 | - dialog.open() | ||
| 265 | - this.playerController.firstPlay(this.audioPlayUrl) | 267 | + // dialog.open() |
| 268 | + this.AudioSuspension.showWindow() | ||
| 269 | + // this.playerController.firstPlay(this.audioPlayUrl) | ||
| 266 | Logger.info("TAG", "cj compInfoBean onClick2 = " + this.isAudioPlaying) | 270 | Logger.info("TAG", "cj compInfoBean onClick2 = " + this.isAudioPlaying) |
| 267 | }) | 271 | }) |
| 268 | } | 272 | } |
| 1 | +import window from '@ohos.window'; | ||
| 1 | import { Logger } from 'wdKit'; | 2 | import { Logger } from 'wdKit'; |
| 2 | import { WDPlayerController } from 'wdPlayer'; | 3 | import { WDPlayerController } from 'wdPlayer'; |
| 4 | +import { BusinessError } from '@ohos.base'; | ||
| 3 | 5 | ||
| 4 | const TAG = 'AudioSuspensionModel' | 6 | const TAG = 'AudioSuspensionModel' |
| 5 | 7 | ||
| @@ -8,10 +10,8 @@ const TAG = 'AudioSuspensionModel' | @@ -8,10 +10,8 @@ const TAG = 'AudioSuspensionModel' | ||
| 8 | */ | 10 | */ |
| 9 | export class AudioSuspensionModel { | 11 | export class AudioSuspensionModel { |
| 10 | public playerController: SubscribedAbstractProperty<WDPlayerController> = AppStorage.link<WDPlayerController>('playerController') | 12 | public playerController: SubscribedAbstractProperty<WDPlayerController> = AppStorage.link<WDPlayerController>('playerController') |
| 11 | - public simpleAudioDialog: CustomDialogController = {} as CustomDialogController | ||
| 12 | - constructor(simpleAudioDialog: CustomDialogController) { | ||
| 13 | - this.simpleAudioDialog = simpleAudioDialog | ||
| 14 | - | 13 | + public floatWindowClass: SubscribedAbstractProperty<window.Window> = AppStorage.link<window.Window>('floatWindowClass') |
| 14 | + constructor() { | ||
| 15 | this.initPlayerController() | 15 | this.initPlayerController() |
| 16 | } | 16 | } |
| 17 | /** | 17 | /** |
| @@ -34,10 +34,28 @@ export class AudioSuspensionModel { | @@ -34,10 +34,28 @@ export class AudioSuspensionModel { | ||
| 34 | // this.playerController.switchPlayOrPause() | 34 | // this.playerController.switchPlayOrPause() |
| 35 | Logger.info(TAG, 'handlePlayer') | 35 | Logger.info(TAG, 'handlePlayer') |
| 36 | } | 36 | } |
| 37 | + // 显示悬浮窗。 | ||
| 38 | + public showWindow() { | ||
| 39 | + this.floatWindowClass.get().showWindow((err: BusinessError) => { | ||
| 40 | + let errCode: number = err.code; | ||
| 41 | + if (errCode) { | ||
| 42 | + console.error('floatWindowClass Failed to show the window. Cause: ' + JSON.stringify(err)); | ||
| 43 | + return; | ||
| 44 | + } | ||
| 45 | + console.info('floatWindowClass Succeeded in showing the window.'); | ||
| 46 | + }); | ||
| 47 | + } | ||
| 37 | 48 | ||
| 38 | - public delete() { | ||
| 39 | - let res: boolean = AppStorage.delete('PropB'); | ||
| 40 | - Logger.info(TAG, `delete: ${res}`) | 49 | + // 销毁悬浮窗 使用destroy对其进行销毁。 |
| 50 | + public destroyWindow() { | ||
| 51 | + this.floatWindowClass.get().destroyWindow((err: BusinessError) => { | ||
| 52 | + let errCode: number = err.code; | ||
| 53 | + if (errCode) { | ||
| 54 | + console.error('floatWindowClass Failed to destroy the window. Cause: ' + JSON.stringify(err)); | ||
| 55 | + return; | ||
| 56 | + } | ||
| 57 | + console.info('floatWindowClass Succeeded in destroying the window.'); | ||
| 58 | + }); | ||
| 41 | } | 59 | } |
| 42 | 60 | ||
| 43 | 61 |
| @@ -18,6 +18,7 @@ | @@ -18,6 +18,7 @@ | ||
| 18 | "wdHwAbility": "file:../../features/wdHwAbility", | 18 | "wdHwAbility": "file:../../features/wdHwAbility", |
| 19 | "wdJsBridge": "file:../../commons/wdJsBridge", | 19 | "wdJsBridge": "file:../../commons/wdJsBridge", |
| 20 | "wdLogin": "file:../../features/wdLogin", | 20 | "wdLogin": "file:../../features/wdLogin", |
| 21 | - "wdTracking": "file:../../features/wdTracking" | 21 | + "wdTracking": "file:../../features/wdTracking", |
| 22 | + "wdPlayer": "file:../../features/wdPlayer" | ||
| 22 | } | 23 | } |
| 23 | } | 24 | } |
| @@ -3,6 +3,7 @@ import hilog from '@ohos.hilog'; | @@ -3,6 +3,7 @@ import hilog from '@ohos.hilog'; | ||
| 3 | import UIAbility from '@ohos.app.ability.UIAbility'; | 3 | import UIAbility from '@ohos.app.ability.UIAbility'; |
| 4 | import Want from '@ohos.app.ability.Want'; | 4 | import Want from '@ohos.app.ability.Want'; |
| 5 | import window from '@ohos.window'; | 5 | import window from '@ohos.window'; |
| 6 | +import { BusinessError } from '@ohos.base'; | ||
| 6 | import { registerRouter } from 'wdRouter'; | 7 | import { registerRouter } from 'wdRouter'; |
| 7 | import { | 8 | import { |
| 8 | EmitterEventId, | 9 | EmitterEventId, |
| @@ -79,6 +80,8 @@ export default class EntryAbility extends UIAbility { | @@ -79,6 +80,8 @@ export default class EntryAbility extends UIAbility { | ||
| 79 | AppStorage.setOrCreate('topSafeHeight', topSafeHeight); | 80 | AppStorage.setOrCreate('topSafeHeight', topSafeHeight); |
| 80 | AppStorage.setOrCreate('windowWidth', width); | 81 | AppStorage.setOrCreate('windowWidth', width); |
| 81 | AppStorage.setOrCreate('windowHeight', height); | 82 | AppStorage.setOrCreate('windowHeight', height); |
| 83 | + let audioWidth = px2vp(width)*0.65 | ||
| 84 | + console.info('floatWindowClass audioWidth' + audioWidth); | ||
| 82 | 85 | ||
| 83 | 86 | ||
| 84 | // let a = new WindowModel(); | 87 | // let a = new WindowModel(); |
| @@ -98,6 +101,48 @@ export default class EntryAbility extends UIAbility { | @@ -98,6 +101,48 @@ export default class EntryAbility extends UIAbility { | ||
| 98 | } | 101 | } |
| 99 | hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); | 102 | hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); |
| 100 | }); | 103 | }); |
| 104 | + // 1.创建悬浮窗 | ||
| 105 | + let floatWindowClass: window.Window | null = null; | ||
| 106 | + const config: window.Configuration = { | ||
| 107 | + name: "floatWindow", windowType: window.WindowType.TYPE_FLOAT, ctx: this.context | ||
| 108 | + }; | ||
| 109 | + window.createWindow(config, (err: BusinessError, data) => { | ||
| 110 | + let errCode: number = err.code; | ||
| 111 | + if (errCode) { | ||
| 112 | + console.error('floatWindowClass Failed to create the floatWindow. Cause: ' + JSON.stringify(err)); | ||
| 113 | + return; | ||
| 114 | + } | ||
| 115 | + console.info('floatWindowClass Succeeded in creating the floatWindow. Data: ' + JSON.stringify(data)); | ||
| 116 | + floatWindowClass = data; | ||
| 117 | + AppStorage.setOrCreate('floatWindowClass', floatWindowClass); | ||
| 118 | + // 2.悬浮窗窗口创建成功后,设置悬浮窗的位置、大小及相关属性等。 | ||
| 119 | + floatWindowClass.moveWindowTo(0, 604, (err: BusinessError) => { | ||
| 120 | + let errCode: number = err.code; | ||
| 121 | + if (errCode) { | ||
| 122 | + console.error('floatWindowClass Failed to move the window. Cause:' + JSON.stringify(err)); | ||
| 123 | + return; | ||
| 124 | + } | ||
| 125 | + console.info('floatWindowClass Succeeded in moving the window.'); | ||
| 126 | + }); | ||
| 127 | + floatWindowClass.resize(800, 200, (err: BusinessError) => { | ||
| 128 | + let errCode: number = err.code; | ||
| 129 | + if (errCode) { | ||
| 130 | + console.error('floatWindowClass Failed to change the window size. Cause:' + JSON.stringify(err)); | ||
| 131 | + return; | ||
| 132 | + } | ||
| 133 | + console.info('floatWindowClass Succeeded in changing the window size.'); | ||
| 134 | + }); | ||
| 135 | + // 3.为悬浮窗加载对应的目标页面。 | ||
| 136 | + floatWindowClass.setUIContent("pages/view/AudioComponent", (err: BusinessError) => { | ||
| 137 | + let errCode: number = err.code; | ||
| 138 | + if (errCode) { | ||
| 139 | + console.error('floatWindowClass Failed to load the content. Cause:' + JSON.stringify(err)); | ||
| 140 | + return; | ||
| 141 | + } | ||
| 142 | + console.info('floatWindowClass Succeeded in loading the content.'); | ||
| 143 | + }); | ||
| 144 | + | ||
| 145 | + }); | ||
| 101 | } | 146 | } |
| 102 | 147 | ||
| 103 | onWindowStageDestroy(): void { | 148 | onWindowStageDestroy(): void { |
| 1 | -import { WDPlayerController, PlayerConstants } from 'wdPlayer'; | ||
| 2 | -import { PaperReaderSimpleDialog } from './PaperReaderDialog'; | ||
| 3 | -import { Logger } from 'wdKit/Index'; | ||
| 4 | -import { AudioSuspensionModel } from '../viewmodel/AudioSuspensionModel'; | 1 | +import { AudioSuspensionModel } from 'wdComponent' |
| 2 | +import { PlayerConstants } from 'wdPlayer' | ||
| 5 | 3 | ||
| 6 | -const TAG = 'AudioDialog'; | ||
| 7 | - | ||
| 8 | -@Preview | ||
| 9 | -@CustomDialog | ||
| 10 | -export struct AudioDialog { | ||
| 11 | - @Consume audioTitle: string; | ||
| 12 | - @Consume currentTime: string; | ||
| 13 | - @Consume totalTime: string; | ||
| 14 | - @Consume progressVal: number; | 4 | +@Entry |
| 5 | +@Component | ||
| 6 | +struct Index { | ||
| 7 | + private AudioSuspension = new AudioSuspensionModel() | ||
| 8 | + @State audioTitle: string = '来了!新闻早班车5月9日'; | ||
| 9 | + @State currentTime: string = '00:03'; | ||
| 10 | + @State totalTime: string = '06:16'; | ||
| 11 | + @State progressVal: number = 20; | ||
| 15 | @State currentStatus: number = 0; | 12 | @State currentStatus: number = 0; |
| 16 | - controllerDetail?: CustomDialogController | ||
| 17 | - | ||
| 18 | - private playerController: WDPlayerController = new WDPlayerController(); | ||
| 19 | - private simpleAudioDialog: CustomDialogController = new CustomDialogController({ | ||
| 20 | - builder: PaperReaderSimpleDialog({ | ||
| 21 | - cancel: this.onCancel, | ||
| 22 | - confirm: this.onConfirm, | ||
| 23 | - playerController: this.playerController | ||
| 24 | - }), | ||
| 25 | - autoCancel: false, | ||
| 26 | - customStyle: true, | ||
| 27 | - alignment: DialogAlignment.CenterStart, | ||
| 28 | - offset: { dx: 12, dy: -150 }, | ||
| 29 | - | ||
| 30 | - }) | ||
| 31 | - | ||
| 32 | - private AudioSuspension = new AudioSuspensionModel(this.simpleAudioDialog) | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - onCancel() { | ||
| 36 | - Logger.info(TAG, "cj2024 onCancel = ") | ||
| 37 | - this.AudioSuspension.setPlayerUrl() | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - /** | ||
| 41 | - * 回调无用 | ||
| 42 | - **/ | ||
| 43 | - onConfirm() { | ||
| 44 | - Logger.info(TAG, "cj2024 onConfirm = ") | ||
| 45 | - // if (this.playerController != undefined) { | ||
| 46 | - // | ||
| 47 | - // } | ||
| 48 | - // this.status = PlayerConstants.STATUS_PAUSE; | ||
| 49 | - // this.playerController?.pause() | ||
| 50 | - } | ||
| 51 | 13 | ||
| 52 | build() { | 14 | build() { |
| 53 | Stack({ alignContent: Alignment.End }) { | 15 | Stack({ alignContent: Alignment.End }) { |
| @@ -61,7 +23,7 @@ export struct AudioDialog { | @@ -61,7 +23,7 @@ export struct AudioDialog { | ||
| 61 | }) | 23 | }) |
| 62 | .width("60%") | 24 | .width("60%") |
| 63 | .height(20) | 25 | .height(20) |
| 64 | - .fontColor($r("app.color.color_222222")) | 26 | + .fontColor('#222222') |
| 65 | .fontSize(14) | 27 | .fontSize(14) |
| 66 | .margin({ top: 10, left: 10 }) | 28 | .margin({ top: 10, left: 10 }) |
| 67 | .alignSelf(ItemAlign.Start) | 29 | .alignSelf(ItemAlign.Start) |
| @@ -77,13 +39,13 @@ export struct AudioDialog { | @@ -77,13 +39,13 @@ export struct AudioDialog { | ||
| 77 | 39 | ||
| 78 | Row() { | 40 | Row() { |
| 79 | Text(this.currentTime) | 41 | Text(this.currentTime) |
| 80 | - .fontSize($r('app.float.font_size_12')) | ||
| 81 | - .fontColor($r('app.color.color_999999')) | 42 | + .fontSize(12) |
| 43 | + .fontColor("#999999") | ||
| 82 | .height("100%") | 44 | .height("100%") |
| 83 | .alignSelf(ItemAlign.Start) | 45 | .alignSelf(ItemAlign.Start) |
| 84 | Text("/" + this.totalTime) | 46 | Text("/" + this.totalTime) |
| 85 | - .fontSize($r('app.float.font_size_12')) | ||
| 86 | - .fontColor($r('app.color.color_999999')) | 47 | + .fontSize(12) |
| 48 | + .fontColor("#999999") | ||
| 87 | .height("100%") | 49 | .height("100%") |
| 88 | .alignSelf(ItemAlign.Start) | 50 | .alignSelf(ItemAlign.Start) |
| 89 | 51 | ||
| @@ -93,7 +55,7 @@ export struct AudioDialog { | @@ -93,7 +55,7 @@ export struct AudioDialog { | ||
| 93 | .margin({ top: 4, left: 10 }) | 55 | .margin({ top: 4, left: 10 }) |
| 94 | 56 | ||
| 95 | Progress({ value: this.progressVal, total: 100, type: ProgressType.Capsule }) | 57 | Progress({ value: this.progressVal, total: 100, type: ProgressType.Capsule }) |
| 96 | - .color($r('app.color.color_ED2800')) | 58 | + .color("#ED2800") |
| 97 | .backgroundColor($r('app.color.white')) | 59 | .backgroundColor($r('app.color.white')) |
| 98 | .width("100%") | 60 | .width("100%") |
| 99 | .height(3) | 61 | .height(3) |
| @@ -110,11 +72,9 @@ export struct AudioDialog { | @@ -110,11 +72,9 @@ export struct AudioDialog { | ||
| 110 | .height(24) | 72 | .height(24) |
| 111 | .margin({ right: 12 }) | 73 | .margin({ right: 12 }) |
| 112 | .onClick(() => { | 74 | .onClick(() => { |
| 113 | - if (this.playerController) { | ||
| 114 | - // this.onConfirm() | ||
| 115 | - this.playerController.switchPlayOrPause() | 75 | + if (this.AudioSuspension.playerController) { |
| 116 | this.AudioSuspension.playerController.get().switchPlayOrPause() | 76 | this.AudioSuspension.playerController.get().switchPlayOrPause() |
| 117 | - this.currentStatus = this.playerController.getStatus() | 77 | + this.currentStatus = this.AudioSuspension.playerController.get().getStatus() |
| 118 | } | 78 | } |
| 119 | }) | 79 | }) |
| 120 | 80 | ||
| @@ -123,19 +83,17 @@ export struct AudioDialog { | @@ -123,19 +83,17 @@ export struct AudioDialog { | ||
| 123 | .width(24) | 83 | .width(24) |
| 124 | .height(24) | 84 | .height(24) |
| 125 | .onClick(() => { | 85 | .onClick(() => { |
| 126 | - if (this.playerController) { | ||
| 127 | - this.playerController.stop() | ||
| 128 | - } | ||
| 129 | - if (this.controllerDetail) { | ||
| 130 | - this.controllerDetail.close() | 86 | + if (this.AudioSuspension.playerController) { |
| 87 | + this.AudioSuspension.playerController.get().stop() | ||
| 88 | + this.AudioSuspension.destroyWindow() | ||
| 131 | } | 89 | } |
| 132 | }) | 90 | }) |
| 133 | }.width(80) | 91 | }.width(80) |
| 134 | .height(60) | 92 | .height(60) |
| 135 | 93 | ||
| 136 | } | 94 | } |
| 137 | - .width("65%") | ||
| 138 | - .height(60) | 95 | + .width('100%') |
| 96 | + .height('100%') | ||
| 139 | .backgroundColor(Color.White) | 97 | .backgroundColor(Color.White) |
| 140 | .borderRadius(2) | 98 | .borderRadius(2) |
| 141 | } | 99 | } |
410 Bytes
201 Bytes
298 Bytes
| @@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
| 14 | "pages/broadcast/BroadcastPage", | 14 | "pages/broadcast/BroadcastPage", |
| 15 | "pages/launchPage/LaunchInterestsHobbiesPage", | 15 | "pages/launchPage/LaunchInterestsHobbiesPage", |
| 16 | "pages/SpacialTopicPage", | 16 | "pages/SpacialTopicPage", |
| 17 | - "pages/column/ColumnPage" | 17 | + "pages/column/ColumnPage", |
| 18 | + "pages/view/AudioComponent" | ||
| 18 | ] | 19 | ] |
| 19 | } | 20 | } |
-
Please register or login to post a comment