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)
        })
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
分享
微博
QQ
微信
回复
2025-01-09 20:22:16


相关问题
subscribeInfo.setDeviceId()没有效果
4716浏览 • 1回复 已解决
HarmonyOS 设置全局字体没有效果
618浏览 • 1回复 待解决
HarmonyOS POP颜色设置了没有效果
689浏览 • 1回复 待解决
HarmonyOS Canvas设置渐变色没有效果
813浏览 • 1回复 待解决
HarmonyOS 相机设置对焦点,没有效果
624浏览 • 1回复 待解决
HarmonyOS .scale没有动画效果
640浏览 • 1回复 待解决