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