• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 = 'avcastpicker_component ';
17
18/**
19 * Definition of av cast picker state.
20 */
21export enum AVCastPickerState {
22  /**
23   * The picker starts showing.
24   */
25  STATE_APPEARING,
26
27  /**
28   * The picker finishes presenting.
29   */
30  STATE_DISAPPEARING,
31}
32
33@Component
34export struct AVCastPicker {
35  /**
36   * Assigns the color of picker component at normal state.
37   */
38  @Prop normalColor: Color | number | string = '#000000';
39
40  /**
41   * Assigns the color of picker component at active state.
42   */
43  @Prop activeColor: Color | number | string = '#000000';
44
45  /**
46   * Picker state change callback.
47   */
48  private onStateChange?: (state: AVCastPickerState) => void;
49
50  build() {
51    Column() {
52      UIExtensionComponent(
53        {
54          abilityName: 'UIExtAbility',
55          bundleName: 'com.hmos.mediacontroller',
56          parameters: {"normalColor": this.normalColor}
57        })
58        .onReceive((data) => {
59          console.info(TAG, `picker state change : ${JSON.stringify(data['state'])}`);
60          if (this.onStateChange != null) {
61            if (parseInt(JSON.stringify(data['state'])) === AVCastPickerState.STATE_APPEARING) {
62              this.onStateChange(AVCastPickerState.STATE_APPEARING);
63            } else {
64              this.onStateChange(AVCastPickerState.STATE_DISAPPEARING);
65            }
66          }
67        })
68      .size({width: '100%', height: '100%'})
69    }.size({width: '100%', height: '100%'})
70  }
71}
72