HarmonyOS 音频面板拉起来没有效果

HarmonyOS
2025-01-09 17:29:24
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

这个需要按音量键调节音量时候会出现,请参考下面的代码控制音量:

import { AVVolumePanel } from '@kit.AudioKit';

@Entry
@Component
struct PanGestureExample {
  @State offsetX: number = 0
  @State offsetY: number = 0
  @State positionX: number = 0
  @State positionY: number = 0
  @State volume: number = 0
  private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Left | PanDirection.Right })
  private volumePanOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down})
  build() {
    Column() {
      Column().height(100)

      AVVolumePanel({
        volumeLevel: this.volume,
        volumeParameter: {
          position: {
            x: 100,
            y: 200
          }
        }
      }).gesture( PanGesture(this.volumePanOption)
        .onActionStart((event: GestureEvent) => {
          console.info('Pan start')
        })
        .onActionUpdate((event: GestureEvent) => {
          if (event) {
            //this.offsetX = this.positionX + event.offsetX
            this.offsetY = this.positionY + event.offsetY
            this.volume = this.offsetY
            console.log("音量是:", this.volume)
          }
        })
        .onActionEnd((event: GestureEvent) => {
          this.positionX = this.offsetX
          this.positionY = this.offsetY
          console.info('Pan end')
        })
      ).backgroundColor(Color.Green)
        .width("10%").height("10%")

      Button('修改PanGesture触发条件')
        .onClick(() => {
          // 将PanGesture手势事件触发条件改为双指以任意方向拖动
          this.panOption.setDirection(PanDirection.All)
          this.panOption.setFingers(2)
        })
    }
  }
}
分享
微博
QQ
微信
回复
2025-01-09 20:22:16
相关问题
subscribeInfo.setDeviceId()没有效果
4381浏览 • 1回复 已解决
HarmonyOS 设置全局字体没有效果
281浏览 • 1回复 待解决
HarmonyOS POP颜色设置了没有效果
342浏览 • 1回复 待解决
HarmonyOS Canvas设置渐变色没有效果
425浏览 • 1回复 待解决
HarmonyOS 相机设置对焦点,没有效果
274浏览 • 1回复 待解决
HarmonyOS .scale没有动画效果
255浏览 • 1回复 待解决