1/*
2 * Copyright (c) 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
16const TAG = 'AVVolumePanel';
17
18class AVVolumePanelParameter {
19  public position?: Position;
20}
21
22@Component
23export struct AVVolumePanel {
24  @Prop@Watch('volumeChange')
25  volumeLevel?: number = 0;
26  @Prop
27  volumeParameter?: AVVolumePanelParameter;
28
29  volumeCallback!: UIExtensionProxy;
30
31  volumeChange() {
32    if (this.volumeCallback != null) {
33      console.info(TAG, `volumeChange volumeLevel = ` + this.volumeLevel);
34      this.volumeCallback.send({'volume': this.volumeLevel});
35    }
36  }
37
38  build() {
39    Column() {
40      UIExtensionComponent(
41        {
42          abilityName: 'AVVolumeExtension',
43          bundleName: 'com.hmos.mediacontroller',
44          parameters: {
45            'volumeParameter': this.volumeParameter,
46          }
47        })
48        .onReceive((data) => {
49          console.info(TAG, `onReceive : ${JSON.stringify(data['state'])}`);
50        })
51        .onRemoteReady((callback: UIExtensionProxy) => {
52          console.info(TAG, `onRemoteReady callback : ${JSON.stringify(callback)}`);
53          this.volumeCallback = callback;
54        })
55        .size({width: '100%', height: '100%'})
56    }.size({width: '100%', height: '100%'})
57  }
58}