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%') } }
HarmonyOS不提供接口给应用切换设备,设备切换只能通过用户完成,如果想提供切换设备的功能,需要集成AVCastPicker组件。