HarmonyOS 鸿蒙Next AVSession偶现创建失败

发布于 1周前 作者 caililin 最后一次编辑是 5天前 来自 鸿蒙OS

HarmonyOS 鸿蒙Next AVSession偶现创建失败
在使用AVSession的过程中,发现avSession的创建偶尔会出错,错误码6600101,通常是上一次成功创建session destroy后再次创建出现错误,在业务中的流程是 createAVSession ->this.session!.activate() -> this.session?.destroy() -> createAVSession

模拟代码简化后如下:


this.session = await AVSessionManager.createAVSession(getContext(this), "TocSessionTag", type ?? 'video')
  .catch((err: BusinessError) => {
    PlayerLog.info(BizTag, "Media.AVSession-1", `Failed to create AVSession, error info: ${JSON.stringify(err)}`);
    ret = false;
    return null;
  });

this.registerListener();

await this.session!.activate().catch((err: BusinessError) => {
  PlayerLog.info(BizTag, "Media.AVSession-1", `Failed to activate AVSession, error info: ${JSON.stringify(err)}`);
  ret = false;
});

if (type === 'video') {
  this.session?.setExtras({ requireAbilityList: ['url-cast'] });
}

this.session?.destroy()

this.session = await AVSessionManager.createAVSession(getContext(this), "TocSessionTag", type ?? 'video')
  .catch((err: BusinessError) => {
    PlayerLog.info(BizTag, "Media.AVSession-2", `Failed to create AVSession, error info: ${JSON.stringify(err)}`);
    ret = false;
    return null;
  });
}

更多关于HarmonyOS 鸿蒙Next AVSession偶现创建失败的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

试一下

this.session?.destroy().then(() => {
  console.info('Destroy : SUCCESS ');
  this.session = await AVSessionManager.createAVSession(getContext(this)
}).catch((err: BusinessError) => {
  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
});

avSession.createAVSession创建会话对象,一个Ability只能存在一个会话,重复创建会失败,销毁完毕之后才能创建新的session实例

更多关于HarmonyOS 鸿蒙Next AVSession偶现创建失败的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙系统中,Next AVSession偶现创建失败的问题可能由多种因素导致。以下是一些直接可能的原因及排查方向:

  1. 资源冲突:检查系统中是否有其他应用或服务占用了必要的音视频资源,导致AVSession创建时资源分配失败。

  2. 权限问题:确保应用已正确申请并获得了使用音视频功能的必要权限,包括摄像头、麦克风等硬件访问权限。

  3. 系统状态:系统负载过高或处于某些特定状态(如低功耗模式)可能影响AVSession的创建。观察问题发生时系统的整体状态。

  4. 版本兼容性:检查应用的鸿蒙系统版本兼容性,确保AVSession的API调用与当前系统版本相匹配。

  5. 错误处理:增强错误处理逻辑,捕获AVSession创建失败的异常,并尝试记录详细的错误信息或日志,以便后续分析。

  6. 代码审查:回顾AVSession创建相关的代码,确认没有逻辑错误或不当的API使用方式。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html 。通过专业客服渠道,可以进一步获取针对性的技术支持和解决方案。

回到顶部
AI 助手
你好,我是IT营的 AI 助手
您可以尝试点击下方的快捷入口开启体验!