1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// @ts-nocheck 17import { myMedia } from '../model/myMedia' 18import { getTimeString } from '../model/TimeTools' 19 20@Component 21export struct BroadcastControl { 22 @State isInformation: boolean = false 23 @Link myMedia: myMedia 24 @Link isXComponent: boolean 25 @Link surfaceId: number 26 @Link isPlaying: boolean 27 @Link currentTime: number 28 private timer: number = undefined 29 private mXComponentController: XComponentController 30 private dialogController: CustomDialogController = null 31 32 build() { 33 Column() { 34 Column() { 35 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 36 Text(this.myMedia.fileName || $r('app.string.phoneMain_title')) 37 .fontColor('rgba(255,255,255,0.90)') 38 .fontSize(18) 39 .width('60%') 40 .margin({ left: 15 }) 41 .fontFamily('HarmonyHeiTi-Medium') 42 .layoutWeight(1) 43 Row() { 44 Image($r('app.media.icon_freeplay')) 45 .width(24) 46 .height(24) 47 .opacity(0.4) 48 .enabled(false) 49 Image($r('app.media.icon_favorite')) 50 .width(24) 51 .height(24) 52 .opacity(0.4) 53 .enabled(false) 54 } 55 .width('20%') 56 .justifyContent(FlexAlign.SpaceEvenly) 57 }.height('15%') 58 59 if (this.isXComponent) { 60 Row() { 61 XComponent({ 62 id: '', 63 type: 'surface', 64 controller: this.mXComponentController 65 }) 66 .onLoad(() => { 67 this.surfaceId = this.mXComponentController.getXComponentSurfaceId() 68 }) 69 .height('70%') 70 .width('100%') 71 } 72 } 73 Blank() 74 Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceEvenly }) { 75 Image(this.isPlaying ? $r('app.media.icon_play') : $r('app.media.icon_pause')) 76 .width(24) 77 .height(24) 78 .onClick(() => { 79 this.isPlaying = !this.isPlaying 80 clearInterval(this.timer) 81 this.timer = setInterval(() => { 82 this.currentTime = this.myMedia.getCurrentTime() 83 }, 1000) 84 }) 85 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 86 Text(getTimeString(this.currentTime) || '00:00') 87 .fontSize(12) 88 .fontColor('#FFFFFF') 89 .fontWeight(500) 90 .opacity(0.6) 91 .fontFamily('HarmonyHeiTi') 92 Slider({ 93 value: this.myMedia ? Math.round(this.currentTime / this.myMedia.totalDuration * 100) : 0 94 }) 95 .selectedColor(Color.White) 96 .width('81%') 97 .trackColor(Color.Gray) 98 .onChange((value: number) => { 99 this.currentTime = this.myMedia.totalDuration * value / 100 100 this.myMedia.seek(this.currentTime) 101 }) 102 Text(this.myMedia ? getTimeString(this.myMedia.totalDuration) : '00:00') 103 .fontSize(12) 104 .fontColor('#FFFFFF') 105 .fontWeight(500) 106 .opacity(0.6) 107 .fontFamily('HarmonyHeiTi') 108 }.width('80%') 109 110 Image($r('app.media.icon_large')) 111 .width(24) 112 .height(24) 113 .opacity(0.4) 114 .enabled(false) 115 }.width('100%').height('15%') 116 }.height('100%') 117 }.height('45%').backgroundColor(Color.Black) 118 } 119}