HarmonyOS 扬声器、听筒如何切换?

如题:HarmonyOS 扬声器、听筒如何切换?

阅读 582
1 个回答

HarmonyOS不提供接口给应用切换设备,设备切换只能通过用户完成,如果想提供切换设备的功能,需要集成AVCastPicker组件。

import AVCastPicker from '@ohos.multimedia.avCastPicker'
import AVSessionManager from '@ohos.multimedia.avsession';

@Entry
@Component
struct Index {
  async onPageShow(){
    // 开始创建并激活媒体会话
    // 创建session
    let context: Context = getContext(this)
    let type: AVSessionManager.AVSessionType = 'voice_call';
    let session = await AVSessionManager.createAVSession(context,'SESSION_NAME', type);
    console.log('AVSession成功:'+JSON.stringify(session))
    // 激活接口要在元数据、控制命令注册完成之后再执行
    await session.activate();
    console.info(`session create done : sessionId : ${session.sessionId}`);
  }
  build() {
    Row() {
      Column() {
        AVCastPicker()
          .width('40vp')
          .height('40vp')
          .border({ width: 1, color: Color.Red })
      }.height('50%')
    }.width('50%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进