| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- import { DeviceUtil, StrUtil } from '@pura/harmony-utils'
- import { resourceManager } from '@kit.LocalizationKit'
- import { deviceInfo } from '@kit.BasicServicesKit'
- import { hdsEffect } from '@kit.UIDesignKit'
- import { VideoItem } from '../viewmodel/VideoItem'
- import { PlayStatus } from '../common/PlayStatus'
- import { CommonConstants } from '../common/constants/CommonConstants'
- import { PointLightContentButton } from './PointLight/PointLightContentButton'
- import { PlayingIndicator } from './PlayingIndicator'
- @Component
- export struct MiniPlayerBar {
- @Prop bottomBarHeight: number = 64
- @Prop bottomSafeHeight: number = 0
- @Prop curDisplayIsHiCar: boolean = false
- @Prop cover: string | undefined = ''
- @Prop currentSong: VideoItem | undefined = undefined
- @Prop themeColor: string = CommonConstants.DEFAULT_THEME_COLOR
- @Prop progressValue: number = 0
- @Prop controlPlayStatus: number = PlayStatus.INIT
- @Prop isShowPrecious: boolean = false
- @Prop isMiniPlayerOrbMode: boolean = false
- @Prop isMiniPlayerModeTransitioning: boolean = false
- @Prop miniPlayerScaleX: number = 1
- @Prop miniPlayerScaleY: number = 1
- @Prop miniPlayerOpacity: number = 1
- @Prop miniPlayerBorderRadius: number = 200
- @Prop miniPlayerProxySize: number = 0
- @Prop miniPlayerProxyOpacity: number = 0
- @Prop miniPlayerContentScaleY: number = 1
- @Prop miniPlayerContentTranslateY: number = 0
- @Prop miniPlayerFullContentTranslateX: number = 0
- @Prop miniPlayerTranslateY: number = 0
- @Prop miniPlayerSurfaceWidth: number = 0
- @Prop miniPlayerSurfaceHeight: number = 0
- @Prop miniPlayerFullContentOpacity: number = 1
- @Prop miniPlayerOrbOpacity: number = 0
- @Prop miniPlayerOrbScale: number = 1
- @Prop miniPlayerOrbTranslateX: number = 0
- onOpenPlayer: () => void = () => {}
- onCollapseToOrb: () => void = () => {}
- onOrbTap: () => void = () => {}
- onPlayPrevious: () => void = () => {}
- onPlayOrPause: () => void = () => {}
- onPlayNext: () => void = () => {}
- onOpenPlayList: () => void = () => {}
- @State private pointLightOptions: hdsEffect.PointLightOptions | undefined = undefined
- private resolveMiniPlayerOrbSize(): number {
- const barHeightVp = this.bottomBarHeight > 0 ? this.bottomBarHeight : 70
- return Math.max(54, Math.min(60, barHeightVp - 8))
- }
- private shouldBlockTransportAction(): boolean {
- return this.isMiniPlayerModeTransitioning
- }
- @Builder
- private buildMiniPlayerMorphProxyDot() {
- Stack({ alignContent: Alignment.Center }) {
- Image(StrUtil.isNotEmpty(this.cover) ? this.cover as string : $r('app.media.alt'))
- .width('100%')
- .height('100%')
- .objectFit(ImageFit.Cover)
- .alt($r('app.media.alt'))
- }
- .width(this.miniPlayerProxySize)
- .height(this.miniPlayerProxySize)
- .borderRadius(this.miniPlayerProxySize)
- .clip(true)
- .opacity(this.miniPlayerProxyOpacity)
- .shadow({
- radius: 18,
- type: ShadowType.BLUR,
- color: 'on_primary'
- })
- }
- @Builder
- private buildMiniPlayerOrbButtonContent(orbSize: number) {
- Stack({ alignContent: Alignment.Center }) {
- Image(StrUtil.isNotEmpty(this.cover) ? this.cover as string : $r('app.media.alt'))
- .width('100%')
- .height('100%')
- .objectFit(ImageFit.Cover)
- .alt($r('app.media.alt'))
- .borderRadius(100)
- Column()
- .width('100%')
- .height('100%')
- .backgroundColor('#66000000')
- Progress({
- value: Math.floor(this.progressValue),
- total: 100,
- type: ProgressType.Ring,
- })
- .color(Color.White)
- .width('100%')
- .height('100%')
- .style({ strokeWidth: 3 })
- if (this.controlPlayStatus === PlayStatus.PLAY) {
- PlayingIndicator({
- isActive: true,
- indicatorSize: Math.max(16, Math.floor(orbSize * 0.34)),
- indicatorColor: '#FFFFFF'
- })
- }
- }
- .width('100%')
- .height('100%')
- .clip(true)
- .borderRadius(100)
- }
- @Builder
- private miniPlayerOrbControl() {
- PointLightContentButton({
- pointColor: this.themeColor,
- buttonRadius: this.resolveMiniPlayerOrbSize() / 2,
- pointLightHeight: 96,
- pressScale: 0.94,
- useShadow: true,
- builder: (): void => {
- this.buildMiniPlayerOrbButtonContent(this.resolveMiniPlayerOrbSize())
- }
- })
- .width(this.resolveMiniPlayerOrbSize())
- .height(this.resolveMiniPlayerOrbSize())
- .opacity(this.miniPlayerOrbOpacity)
- .borderRadius(this.resolveMiniPlayerOrbSize() / 2)
- .scale({ x: this.miniPlayerOrbScale, y: this.miniPlayerOrbScale, centerX: '50%', centerY: '50%' })
- .translate({ x: this.miniPlayerOrbTranslateX })
- .onClick((): void => {
- this.onOrbTap()
- })
- }
- @Builder
- private buildMiniPlayerCoverContent() {
- Stack({ alignContent: Alignment.Center }) {
- Image(StrUtil.isNotEmpty(this.currentSong?.pixelMapPath) ?
- this.currentSong?.pixelMapPath : $r('app.media.alt'))
- .width(48)
- .height(48)
- .objectFit(ImageFit.Contain)
- .alt($r('app.media.alt'))
- .fillColor(this.themeColor)
- .borderRadius(8)
- .shadow({
- radius: 15,
- type: ShadowType.BLUR,
- color: 'on_primary'
- })
- }
- .width(48)
- .height(48)
- }
- @Builder
- private miniPlayerCoverButton() {
- PointLightContentButton({
- pointColor: this.themeColor,
- buttonRadius: 10,
- pointLightHeight: 88,
- pressScale: 0.92,
- useShadow: false,
- builder: (): void => {
- this.buildMiniPlayerCoverContent()
- }
- })
- .width(48)
- .height(48)
- .margin({ left: 5 })
- .zIndex(3)
- .onClick((): void => {
- this.onCollapseToOrb()
- })
- }
- @Builder
- private buildPlayPreviousControlContent() {
- Row() {
- SymbolGlyph($r('sys.symbol.backward_end_fill'))
- .fontSize(28)
- .fontColor([Color.White])
- }
- .width('100%')
- .height('100%')
- .justifyContent(FlexAlign.Center)
- .alignItems(VerticalAlign.Center)
- }
- @Builder
- private buildPlayToggleControlContent() {
- Row() {
- Stack() {
- Progress({
- value: Math.floor(this.progressValue),
- type: ProgressType.Ring,
- })
- .color(this.themeColor)
- .height(38)
- .aspectRatio(CommonConstants.ASPECT_RATIO)
- Image(this.controlPlayStatus === PlayStatus.PLAY ? $r('app.media.hm_pause') : $r('app.media.hm_play2'))
- .height(36)
- .width(36)
- .fillColor(Color.White)
- }
- }
- .width('100%')
- .height('100%')
- .justifyContent(FlexAlign.Center)
- .alignItems(VerticalAlign.Center)
- }
- @Builder
- private buildPlayNextControlContent() {
- Row() {
- SymbolGlyph($r('sys.symbol.forward_end_fill'))
- .fontSize(28)
- .fontColor([Color.White])
- }
- .width('100%')
- .height('100%')
- .justifyContent(FlexAlign.Center)
- .alignItems(VerticalAlign.Center)
- }
- @Builder
- private buildPlayListControlContent() {
- Row() {
- SymbolGlyph($r('sys.symbol.music_note_list'))
- .fontSize(28)
- .fontColor([Color.White])
- }
- .width('100%')
- .height('100%')
- .justifyContent(FlexAlign.Center)
- .alignItems(VerticalAlign.Center)
- }
- @Builder
- private playConLeft() {
- Row() {
- this.miniPlayerCoverButton()
- Column() {
- Text(this.currentSong?.name)
- .fontSize(16)
- .textOverflow({ overflow: TextOverflow.MARQUEE })
- .maxLines(1)
- .fontColor(Color.White)
- .fontWeight(FontWeight.Bolder)
- Row() {
- Text(this.currentSong?.artist)
- .margin({ top: 2 })
- .fontSize(13)
- .textAlign(TextAlign.Start)
- .maxLines(1)
- .fontWeight(FontWeight.Bold)
- .textOverflow({ overflow: TextOverflow.MARQUEE })
- .fontColor(Color.White)
- }
- .visibility(this.currentSong?.artist ? Visibility.Visible : Visibility.None)
- }
- .padding({ left: 8 })
- .alignItems(HorizontalAlign.Start)
- .margin({ right: 22 })
- .onClick((): void => {
- this.onOpenPlayer()
- })
- }
- .padding({ right: 18 })
- .layoutWeight(1)
- .alignItems(VerticalAlign.Center)
- .justifyContent(FlexAlign.Start)
- }
- @Builder
- private playConRigth() {
- Row() {
- PointLightContentButton({
- pointColor: this.themeColor,
- buttonRadius: 22,
- pointLightHeight: 56,
- pressScale: 0.88,
- builder: (): void => {
- this.buildPlayPreviousControlContent()
- }
- })
- .width(44)
- .height(44)
- .visibility(this.isShowPrecious ? Visibility.Visible : Visibility.None)
- .displayPriority(2)
- .onClick((): void => {
- if (this.shouldBlockTransportAction()) {
- return
- }
- this.onPlayPrevious()
- })
- PointLightContentButton({
- pointColor: this.themeColor,
- buttonRadius: 23,
- pointLightHeight: 62,
- pressScale: 0.9,
- builder: (): void => {
- this.buildPlayToggleControlContent()
- }
- })
- .width(46)
- .height(46)
- .displayPriority(3)
- .onClick((): void => {
- if (this.shouldBlockTransportAction()) {
- return
- }
- this.onPlayOrPause()
- })
- PointLightContentButton({
- pointColor: this.themeColor,
- buttonRadius: 22,
- pointLightHeight: 56,
- pressScale: 0.88,
- builder: (): void => {
- this.buildPlayNextControlContent()
- }
- })
- .width(44)
- .height(44)
- .displayPriority(2)
- .onClick((): void => {
- if (this.shouldBlockTransportAction()) {
- return
- }
- this.onPlayNext()
- })
- PointLightContentButton({
- pointColor: this.themeColor,
- buttonRadius: 21,
- pointLightHeight: 52,
- pressScale: 0.88,
- builder: (): void => {
- this.buildPlayListControlContent()
- }
- })
- .width(42)
- .height(42)
- .displayPriority(1)
- .onClick((): void => {
- if (this.shouldBlockTransportAction()) {
- return
- }
- this.onOpenPlayList()
- })
- }
- .margin({ left: 5 })
- .justifyContent(FlexAlign.End)
- .alignItems(VerticalAlign.Center)
- }
- @Builder
- private hiCarLeadingCluster() {
- Row() {
- this.miniPlayerCoverButton()
- this.hiCarPlayConRigth()
- Row()
- .layoutWeight(1)
- }
- .width('100%')
- .height('100%')
- .justifyContent(FlexAlign.Start)
- .alignItems(VerticalAlign.Center)
- }
- @Builder
- private hiCarCenterInfo() {
- Column() {
- Text(this.currentSong?.name)
- .fontSize(16)
- .textOverflow({ overflow: TextOverflow.MARQUEE })
- .maxLines(1)
- .textAlign(TextAlign.Center)
- .fontColor(Color.White)
- .fontWeight(FontWeight.Bolder)
- Row() {
- Text(this.currentSong?.artist)
- .margin({ top: 2 })
- .fontSize(13)
- .textAlign(TextAlign.Center)
- .maxLines(1)
- .fontWeight(FontWeight.Bold)
- .textOverflow({ overflow: TextOverflow.MARQUEE })
- .fontColor(Color.White)
- }
- .visibility(this.currentSong?.artist ? Visibility.Visible : Visibility.None)
- }
- .width('42%')
- .alignItems(HorizontalAlign.Center)
- .onClick((): void => {
- this.onOpenPlayer()
- })
- }
- @Builder
- private hiCarPlayConRigth() {
- Row({ space: 8 }) {
- PointLightContentButton({
- pointColor: this.themeColor,
- buttonRadius: 22,
- pointLightHeight: 56,
- pressScale: 0.88,
- builder: (): void => {
- this.buildPlayPreviousControlContent()
- }
- })
- .width(44)
- .height(44)
- .visibility(this.isShowPrecious ? Visibility.Visible : Visibility.None)
- .displayPriority(2)
- .onClick((): void => {
- if (this.shouldBlockTransportAction()) {
- return
- }
- this.onPlayPrevious()
- })
- PointLightContentButton({
- pointColor: this.themeColor,
- buttonRadius: 23,
- pointLightHeight: 62,
- pressScale: 0.9,
- builder: (): void => {
- this.buildPlayToggleControlContent()
- }
- })
- .width(46)
- .height(46)
- .displayPriority(3)
- .onClick((): void => {
- if (this.shouldBlockTransportAction()) {
- return
- }
- this.onPlayOrPause()
- })
- PointLightContentButton({
- pointColor: this.themeColor,
- buttonRadius: 22,
- pointLightHeight: 56,
- pressScale: 0.88,
- builder: (): void => {
- this.buildPlayNextControlContent()
- }
- })
- .width(44)
- .height(44)
- .displayPriority(2)
- .onClick((): void => {
- if (this.shouldBlockTransportAction()) {
- return
- }
- this.onPlayNext()
- })
- PointLightContentButton({
- pointColor: this.themeColor,
- buttonRadius: 21,
- pointLightHeight: 52,
- pressScale: 0.88,
- builder: (): void => {
- this.buildPlayListControlContent()
- }
- })
- .width(42)
- .height(42)
- .displayPriority(1)
- .onClick((): void => {
- if (this.shouldBlockTransportAction()) {
- return
- }
- this.onOpenPlayList()
- })
- }
- .margin({ left: 16 })
- .justifyContent(FlexAlign.Start)
- .alignItems(VerticalAlign.Center)
- }
- @Builder
- private playController() {
- Row() {
- this.playConLeft()
- this.playConRigth()
- }
- .width('100%')
- .height(this.bottomBarHeight)
- .scale({ x: 1, y: this.miniPlayerContentScaleY, centerX: '50%', centerY: '50%' })
- .translate({ y: this.miniPlayerContentTranslateY })
- .hitTestBehavior(HitTestMode.Transparent)
- .zIndex(2)
- .opacity(0.9)
- .onClick((): void => {
- this.onOpenPlayer()
- })
- .onTouch((event: TouchEvent): void => {
- if (event.type === TouchType.Down) {
- this.pointLightOptions = {
- color: this.themeColor,
- intensity: 1,
- height: 60
- }
- } else if (event.type === TouchType.Up || event.type === TouchType.Cancel) {
- this.pointLightOptions = undefined
- }
- })
- .visualEffect(deviceInfo.sdkApiVersion >= 20
- ? new hdsEffect.HdsEffectBuilder()
- .pointLight({
- options: this.pointLightOptions,
- illuminatedType: hdsEffect.PointLightIlluminatedType.BORDER_CONTENT
- })
- .buildEffect()
- : undefined)
- .padding({
- left: 16,
- right: 16
- })
- }
- @Builder
- private hiCarPlayController() {
- Stack({ alignContent: Alignment.Center }) {
- this.hiCarLeadingCluster()
- this.hiCarCenterInfo()
- }
- .opacity(0.9)
- .width('100%')
- .height(this.bottomBarHeight)
- .hitTestBehavior(HitTestMode.Transparent)
- .zIndex(2)
- .onClick((): void => {
- this.onOpenPlayer()
- })
- .onTouch((event: TouchEvent): void => {
- if (event.type === TouchType.Down) {
- this.pointLightOptions = {
- color: this.themeColor,
- intensity: 1,
- height: 60
- }
- } else if (event.type === TouchType.Up || event.type === TouchType.Cancel) {
- this.pointLightOptions = undefined
- }
- })
- .visualEffect(deviceInfo.sdkApiVersion >= 20
- ? new hdsEffect.HdsEffectBuilder()
- .pointLight({
- options: this.pointLightOptions,
- illuminatedType: hdsEffect.PointLightIlluminatedType.BORDER_CONTENT
- })
- .buildEffect()
- : undefined)
- .padding({
- left: 16,
- right: 16
- })
- }
- build() {
- Row() {
- Stack() {
- if (!this.isMiniPlayerOrbMode || this.miniPlayerFullContentOpacity > 0.02) {
- Stack() {
- if (this.curDisplayIsHiCar) {
- this.hiCarPlayController()
- } else {
- this.playController()
- }
- }
- .width('100%')
- .height('100%')
- .opacity(this.miniPlayerFullContentOpacity)
- .translate({ x: this.miniPlayerFullContentTranslateX })
- }
- if (this.isMiniPlayerOrbMode || this.miniPlayerOrbOpacity > 0.02) {
- Row() {
- this.miniPlayerOrbControl()
- }
- .width('100%')
- .height('100%')
- .justifyContent(FlexAlign.End)
- .alignItems(VerticalAlign.Center)
- }
- if (this.miniPlayerProxySize > 0) {
- this.buildMiniPlayerMorphProxyDot()
- }
- }
- .width(this.miniPlayerSurfaceWidth)
- .height(this.miniPlayerSurfaceHeight)
- .borderRadius(this.miniPlayerBorderRadius)
- .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
- .backgroundImage(StrUtil.isEmpty(this.cover) ? $r('app.media.alt') : this.cover)
- .backgroundImageSize({ width: '100%' })
- .scale({ x: this.miniPlayerScaleX, y: this.miniPlayerScaleY, centerX: '50%', centerY: '50%' })
- .opacity(Math.min(0.98, this.miniPlayerOpacity))
- .clip(true)
- .clickEffect({ level: ClickEffectLevel.HEAVY })
- }
- .width('90%')
- .height(this.bottomBarHeight)
- .justifyContent(FlexAlign.End)
- .alignItems(VerticalAlign.Center)
- .translate({ y: this.miniPlayerTranslateY })
- .margin({
- bottom: DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_2IN1 || this.curDisplayIsHiCar
- ? 30 : this.bottomSafeHeight
- })
- }
- }
|