• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024-2025 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
16const TAG = 'AVVolumePanel';
17const MAX_PANEL_LIMIT = 20;
18
19class AVVolumePanelParameter {
20  public position?: Position;
21}
22
23@Component
24export struct AVVolumePanel {
25  @Prop@Watch('volumeChange')
26  volumeLevel?: number = 0;
27  @Prop
28  volumeParameter?: AVVolumePanelParameter;
29
30  /*
31   * UIExtensionProxy.
32   */
33  private volumeCallback!: UIExtensionProxy;
34  private panelCountOncreation: number = 0;
35  @State isDisabledByPanelLimit: boolean = false;
36
37  private static currentPanelCount: number = 0;
38
39  volumeChange() {
40    if (this.volumeCallback != null) {
41      console.info(TAG, `volumeChange volumeLevel = ` + this.volumeLevel);
42      this.volumeCallback.send({'volume': this.volumeLevel});
43    }
44  }
45
46  aboutToAppear(): void {
47    AVVolumePanel.currentPanelCount += 1;
48    this.panelCountOncreation = AVVolumePanel.currentPanelCount;
49    if (this.panelCountOncreation > MAX_PANEL_LIMIT) {
50      console.info(TAG, 'disable panel');
51      this.isDisabledByPanelLimit = true;
52    }
53  }
54
55  aboutToDisAppear(): void {
56    AVVolumePanel.currentPanelCount -= 1;
57  }
58
59  build() {
60    Column() {
61      if (this.isDisabledByPanelLimit) {
62        Column();
63      } else {
64        UIExtensionComponent(
65        {
66          abilityName: 'AVVolumeExtension',
67          bundleName: 'com.hmos.mediacontroller',
68          parameters: {
69            'volumeParameter': this.volumeParameter,
70            'ability.want.params.uiExtensionType': 'sysPicker/mediaControl',
71            'currentPanelCount': this.panelCountOncreation,
72          }
73        })
74        .onReceive((data) => {
75          console.info(TAG, `onReceive : ${JSON.stringify(data['state'])}`);
76        })
77        .onRemoteReady((callback: UIExtensionProxy) => {
78          console.info(TAG, `onRemoteReady callback : ${JSON.stringify(callback)}`);
79          this.volumeCallback = callback;
80        })
81        .size({width: '100%', height: '100%'})
82      }
83    }.size({width: '100%', height: '100%'})
84  }
85}