• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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*/
15import router from '@ohos.router';
16import audio from '@ohos.multimedia.audio';
17import display from '@ohos.display';
18import { AVVolumePanel } from '@ohos.multimedia.avVolumePanel';
19
20@Entry
21@Component
22struct VolumePanel {
23  @State private curMediaVolume: number = 0;
24  private audioManager: audio.AudioManager = audio.getAudioManager();
25  private audioVolumeManager: audio.AudioVolumeManager | undefined = undefined;
26
27  aboutToAppear(): void {
28    this.audioVolumeManager = this.audioManager.getVolumeManager();
29    this.audioVolumeManager?.on('volumeChange', async (data) => {
30      let event: audio.VolumeEvent = data;
31      this.curMediaVolume = event.volume;
32    })
33  }
34
35  build() {
36    Column() {
37      Row() {
38        Navigation() {
39          NavRouter() {
40            NavDestination() {
41            }
42          }
43        }
44        .height('100%')
45        .width('100%')
46        .hideBackButton(false)
47        .titleMode(NavigationTitleMode.Mini)
48        .title($r('app.string.AVVOLUME_PANEL_TITLE'))
49        .mode(NavigationMode.Stack);
50      }.height(56).width('100%').id('back_btn_focus')
51      .onClick(async () => {
52        await router.pushUrl({ url: 'pages/Index' });
53      });
54
55      Column() {
56        Row() {
57          Button() {
58            Text($r('app.string.VOLUME_UP')).fontSize(22).fontColor(Color.White)
59          }.width('49%').height(60).onClick(() => {
60            this.curMediaVolume++;
61          })
62
63          Button() {
64            Text($r('app.string.VOLUME_DOWN')).fontSize(22).fontColor(Color.White)
65          }.width('49%').height(60).onClick(() => {
66            this.curMediaVolume--;
67          })
68        }.margin(({ top: 10 })).width('100%').justifyContent(FlexAlign.SpaceBetween)
69
70        AVVolumePanel({
71          volumeLevel: this.curMediaVolume,
72          volumeParameter: {
73            position: {
74              x: display.getDefaultDisplaySync().width / 2 - vp2px(20),
75              y: display.getDefaultDisplaySync().height / 2 - vp2px(83)
76            }
77          }
78        })
79      }
80    }
81  }
82}