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 17 18import { myMedia } from '../model/myMedia' 19 20@Component 21export struct StreamingMedia { 22 @State httpUrl: string = '' 23 @State isEnabled: boolean = false 24 @Link streamOpacity: number 25 @Link streamBackgroundColor: string 26 @Link myMedia: myMedia 27 @Link isXComponent: boolean 28 @Link isPlaying: boolean 29 @Link isShowMenu: boolean 30 @Link streamBtnText: string | Resource 31 @Link isStreamShow: boolean 32 @Link currentTime: number 33 private timer: number = undefined 34 private timerOut: number = undefined 35 private mXComponentController: XComponentController 36 37 build() { 38 Row() { 39 TextInput({ placeholder: $r('app.string.streamMedia_inputText') }) 40 .placeholderColor("rgba(255,255,255,0.60)") 41 .placeholderFont({ size: 16, family: "HarmonyHeiTi", style: FontStyle.Normal }) 42 .textAlign(TextAlign.Center) 43 .caretColor(Color.White) 44 .fontSize(16) 45 .fontFamily("HarmonyHeiTi") 46 .fontStyle(FontStyle.Normal) 47 .fontColor("rgba(255,255,255,0.60)") 48 .borderRadius("24px 0px 0px 24px") 49 .backgroundColor('#343434') 50 .width('100%') 51 .onChange((value: string) => { 52 this.isEnabled = true 53 this.httpUrl = value 54 this.streamOpacity = 1 55 this.streamBackgroundColor = '#5291FF' 56 }) 57 Button({ type: ButtonType.Normal, stateEffect: true }) { 58 Row() { 59 if (this.isStreamShow) { 60 Image($r('app.media.icon_note')).width(24).height(24).margin({ left: 12 }) 61 } 62 Text(this.streamBtnText) 63 .fontSize(16) 64 .align(Alignment.Center) 65 .fontColor('#FFFFFF') 66 .margin({ left: 5, right: 12, top: 2 }) 67 .fontFamily('HarmonyHeiTi-Medium') 68 } 69 .alignItems(VerticalAlign.Center) 70 .justifyContent(FlexAlign.SpaceEvenly) 71 } 72 .width(120) 73 .enabled(this.isEnabled) 74 .height(40) 75 .opacity(this.streamOpacity) 76 .backgroundColor(this.streamBackgroundColor) 77 .borderRadius('100px 24px 24px 100px') 78 .position({ x: '88%', y: '0' }) 79 .onClick(() => { 80 this.streamBtnText = $r('app.string.streamMedia_Playing') 81 this.isStreamShow = true 82 this.isShowMenu = true 83 this.isPlaying = true 84 this.isXComponent = true 85 if (this.timerOut !== undefined) { 86 clearTimeout(this.timerOut) 87 } 88 console.info('zyk' + 'http' + this.httpUrl) 89 this.timerOut = setTimeout(() => { 90 let surfaceId = this.mXComponentController.getXComponentSurfaceId() 91 this.myMedia.httpInit(this.httpUrl, surfaceId) 92 }, 100) 93 if (this.timer !== undefined) { 94 clearInterval(this.timer) 95 } 96 this.timer = setInterval(() => { 97 this.currentTime = this.myMedia.getCurrentTime() 98 }, 1000) 99 }) 100 }.width('79%').margin({ right: 4 }) 101 } 102}