AudioInputRoutingTypeC.ets 7.4 KB
Newer Older
Q
qinliwen 已提交
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import {CustomContainer} from '../common/AudioContainer';
import FirstDialog from '../model/FirstDialog';
import AudioCapturer from '../model/AudioCapturer'
import Logger from '../model/Logger'
import prompt from '@ohos.prompt';
import audio from '@ohos.multimedia.audio'
import router from '@ohos.router';
import mediaPlay from '../model/mediaPlay'
@Entry
@Component
struct audioInputRouting {
  @State name: string = 'AudioInputRoutingTest(TypeC)';
  @State StepTips: string = '请参考提示信息依次执行如下操作';
  @State Vue: boolean = false;
  private tag: string = 'qlw'
  @State deviceChange: audio.DeviceChangeAction = undefined
  @State audioRoutingManager: audio.AudioRoutingManager = undefined
  @State yesEnable: boolean = false
  @State recorderEnable: boolean = false
  @State stopEnable: boolean = false
  @State playEnable: boolean = false
  @State inputDevice: string = ''
  async aboutToAppear(){
    await FirstDialog.ChooseDialog(this.StepTips,this.name);
    await this.onDeviceChange()
    await this.getDevices()
  }
  onPageHide() {
    AudioCapturer.releaseCapturer()
    Logger.info(this.tag, `onPageHide releaseCapturer end`)
    mediaPlay.release()
    Logger.info(this.tag, `onPageHide releaseAVplayer end`)
  }

  async onDeviceChange(){
    this.audioRoutingManager = await audio.getAudioManager().getRoutingManager()
    this.audioRoutingManager.on('deviceChange', audio.DeviceFlag.ALL_DEVICES_FLAG, async(DeviceChangeAction) => {
      Logger.info(this.tag, `deviceChange: ` + JSON.stringify(DeviceChangeAction))
      await this.getDevices()
    })
  }

  async getDevices(){
    try{
      Logger.info(this.tag, `getDevices test `)
      let deviceDescriptors = await this.audioRoutingManager.getDevices(audio.DeviceFlag.INPUT_DEVICES_FLAG)
      Logger.info(this.tag, `getDevices: ` + JSON.stringify(deviceDescriptors))
      switch (deviceDescriptors[0].deviceType) {
        case 3:
          this.inputDevice = "3.5mm有线耳机"
          break
        case 8:
          this.inputDevice = "蓝牙耳机"
          break
        case 15:
          this.inputDevice = "mic"
          break
        case 22:
          this.inputDevice = "Type C"
          break
        default:
          break
      }
      Logger.info(this.tag, `InputDeviceList: ${this.inputDevice}`)
    }catch(err){
      Logger.info(this.tag, `getDevices err message: ${err.message}, err code: ${err.code} `)
    }
  }

  build() {
    Column() {
      Row() {
        Button(){
          Image($r('app.media.ic_public_back')).width('20vp').height('18vp').margin({left:'20vp'})
89
        }.backgroundColor(Color.Black).size({ width: '40vp', height: '30vp' })
Q
qinliwen 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        .onClick(()=>{
          router.back({
            url:'pages/Audio/Audio_index',
            params: {result : 'None',}
          })
        })
        Text(this.name).fontColor(Color.White).fontSize('18fp').margin({left:'-20vp'})
        Text('hello').fontColor(Color.White).visibility(Visibility.Hidden)
      }.backgroundColor(Color.Black).height('10%').width('100%').justifyContent(FlexAlign.SpaceBetween)
      Column() {
        Flex({direction:FlexDirection.Column,alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
          Column(){
            Row(){
              Text(`是否设备支持TypeC耳机?`).fontColor(Color.White).fontSize('18fp')
            }
            Row(){
              Column(){
T
tianwenzhe 已提交
107
                Button(`不支持`)
Q
qinliwen 已提交
108 109 110 111 112 113 114 115 116 117
                  .borderRadius(8)
                  .backgroundColor(0x317aff)
                  .width('30%')
                  .enabled(!this.yesEnable)
                  .opacity(!this.yesEnable? 1 : 0.4)
                  .onClick(async () => {
                    this.Vue = true
                  })
              }
              Column(){
T
tianwenzhe 已提交
118
                Button(`支持`)
Q
qinliwen 已提交
119 120 121 122 123 124 125 126 127 128
                  .borderRadius(8)
                  .backgroundColor(0x317aff)
                  .width('30%')
                  .onClick(async () => {
                    this.yesEnable = true
                    this.recorderEnable = true
                  })
              }
            }
            Row(){
T
tianwenzhe 已提交
129
              Text('测试目的:\n当设备连接TypeC耳机时,是否音频输入路由正确切换\n测试准备\n断连任何外设,保持设备常亮\n测试步骤:\n1. 验证设备是否支持TypeC耳机\n2. 连接TypeC耳机\n3. 按下录制按钮\n4. 对着耳机mic讲话\n5. 按下停止按钮\n6. 按下播放按钮\n测试标准:\n如果设备不支持TypeC耳机输入或者接收到输入路由通知、路由显示为TypeC耳机,通过TypeC可正常录制和播放,则用例pass').fontColor(Color.White).fontSize('18fp')
Q
qinliwen 已提交
130 131 132 133 134 135
            }
            Row(){
              Text(`Audio输入路由:${this.inputDevice}`).fontColor(Color.White).fontSize('18fp')
            }
            Row(){
              Column(){
T
tianwenzhe 已提交
136
                Button(`录制`)
Q
qinliwen 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149
                  .borderRadius(8)
                  .backgroundColor(0x317aff)
                  .width('30%')
                  .enabled(this.recorderEnable)
                  .opacity(this.recorderEnable ? 1 : 0.4)
                  .onClick(async () => {
                    this.stopEnable = true
                    this.recorderEnable = false
                    await AudioCapturer.createAudioCapturer()
                    await AudioCapturer.startCapturer()
                  })
              }
              Column(){
T
tianwenzhe 已提交
150
                Button(`停止`)
Q
qinliwen 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164
                  .borderRadius(8)
                  .backgroundColor(0x317aff)
                  .width('30%')
                  .enabled(this.stopEnable)
                  .opacity(this.stopEnable ? 1 : 0.4)
                  .onClick(async () => {
                    this.recorderEnable = true
                    this.stopEnable = false
                    this.playEnable = true
                    await AudioCapturer.stopCapturer()
                    await AudioCapturer.releaseCapturer()
                  })
              }
              Column(){
T
tianwenzhe 已提交
165
                Button(`播放`)
Q
qinliwen 已提交
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
                  .borderRadius(8)
                  .backgroundColor(0x317aff)
                  .width('30%')
                  .enabled(this.playEnable)
                  .opacity(this.playEnable ? 1 : 0.4)
                  .onClick(async () => {
                    this.playEnable = false
                    await mediaPlay.init()
                    this.Vue = true
                  })
              }
            }
          }

        }
      }.width('100%').height('80%').backgroundColor(Color.Black)
      .justifyContent(FlexAlign.SpaceEvenly)
      CustomContainer({
        title: this.name,
        Url:'pages/Audio/Audio_index',
        StepTips:this.StepTips,
        name:$name,
        Vue: $Vue,
      }).height('10%').width('100%')
    }.width('100%').height('100%').backgroundColor(Color.Black)
  }
192 193 194 195 196
  onBackPress(){
    router.replaceUrl({
      url:'pages/Audio/Audio_index',
    })
  }
Q
qinliwen 已提交
197
}