RTC Engine
  • 产品概述
  • Web
    • 跑通 Demo
    • SDK 快速启动
    • 基础功能
      • 屏幕分享
      • 直播
      • 媒体设备
      • 音量
      • 设置编码配置文件
      • 检测网络质量
      • 检测能力
    • 高级功能
      • 启用 AI 降噪
      • 启用混音
      • 启用水印
      • Enable Virtual Background
      • 启用美颜和特效
      • 数据消息
      • 自定义采集和渲染
    • 接口列表
    • 发布说明
    • 支持平台
    • Web 常见问题
      • 优化多人视频通话
      • 处理自动播放受限
      • 应对防火墙限制
      • 其他
  • Android
    • Run Sample Code
    • Integration
    • 集成
      • 7. 检测网络质量
      • 8. 开启屏幕共享
      • 9. 设置视频质量
      • 10. 旋转视频
    • Advanced Features
      • 测试网络质量
      • 自定义采集和渲染
      • 自定义音频采集和播放
    • 客户端API
      • 产品概述
      • TRTCCloud
      • TRTCStatistics
      • TRTCCloudListener
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • 类型定义
      • 废弃接口
      • 错误码
    • 解决方案
      • 实时合唱 (TUIKaraoke)
        • 快速集成
        • 实施步骤
        • 歌曲同步
        • 歌词同步
        • 语音同步
        • 混流解决方案
        • TRTCKaraoke 相关接口
        • 常见问题
    • 发布说明
  • iOS
    • Run Sample Code
    • Integration
    • 集成
      • 7. 检测网络质量
      • 8. 开启屏幕共享
      • 9. 设置视频质量
      • 10. 旋转视频
    • Advanced Features
      • 测试网络质量
      • 自定义采集和渲染
      • 自定义音频采集和播放
    • 客户端API
      • 产品概述
      • TRTCCloud
      • TRTCCloudDelegate
      • TRTCStatistics
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • 类型定义
      • 废弃接口
      • ErrorCode
    • 解决方案
      • 快速集成
      • 实施步骤
      • 歌曲同步
      • 歌词同步
      • 语音同步
      • 混流解决方案
      • TRTCKaraoke 相关接口
      • 常见问题
    • 发布说明
  • macOS
    • Run Sample Code
    • Integration
    • 集成
      • 7. 检测网络质量
      • 8. 开启屏幕共享
      • 9. 共享电脑声音
      • 10. 设置视频质量
      • 11. 旋转视频
    • Advanced Features
      • 测试硬件设备
      • 测试网络质量
      • 自定义采集和渲染
      • 自定义音频采集和播放
    • 客户端API
      • 产品概述
      • TRTCCloud
      • TRTCCloudDelegate
      • TRTCStatistics
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • 类型定义
      • 废弃接口
      • ErrorCode
      • 发布说明
    • 发布说明
  • Windows
    • Run Sample Code
    • Integration
    • 集成
      • 7. 检测网络质量
      • 8. 开启屏幕共享
      • 9. 设置视频质量
      • 10. 旋转视频
    • Advanced Features
      • 测试硬件设备
      • 测试网络质量
      • 自定义采集和渲染
      • 自定义音频采集和播放
    • 客户端API
      • 产品概述
      • ITRTCCloud
      • ITRTCStatistics
      • TRTCCloudCallback
      • ITXAudioEffectManager
      • ITXDeviceManager
      • 类型定义
      • 废弃接口
      • 错误码
    • 发布说明
  • Electron
    • 集成
      • 1. 接口示例
      • 2. 导入 SDK
      • 3. 进入房间
      • 4. 订阅音视频流
      • 5. 发布音视频流
      • 6. 退出房间
      • 7. 检测网络质量
      • 8. 开启屏幕共享
      • 9. 共享电脑声音
      • 10. 设置视频质量
      • 11. 旋转视频
    • 客户端API
      • 产品概述
      • 错误码
  • Flutter
    • 集成
      • 1. 接口示例
      • 2. 导入 SDK
      • 3. 进入房间
      • 4. 订阅音视频流
      • 5. 发布音视频流
      • 6. 退出房间
      • 7. 检测网络质量
      • 8. 开启屏幕共享
      • 9. 共享电脑声音
      • 10. 设置视频质量
      • 11. 旋转视频
    • 客户端API
      • 产品概述
      • 错误码
  • Unity
    • 集成
      • 1. 接口示例
      • 2. 导入 SDK
    • 客户端API
      • 产品概述
      • 错误码
  • QT
    • 集成
      • 1. 导入 SDK
  • 产品概述
    • 产品概述
  • 概念
  • 产品特性
  • 性能统计
  • 价格中心
    • 免费时长
    • RTC-Engine 套餐
    • 订阅套餐时长计费说明
    • 现收现付
      • 音视频时长计费说明
      • 云端录制计费说明
      • 混流转码与旁路转推计费说明
  • 常见问题
    • 入门常见问题
    • 迁移指南
      • Twilio Video 到 TRTC 的迁移
      • 计费
      • 产品特性
      • UserSig
      • 防火墙限制
      • 如何缩减安装包
      • TRTCCalling Web 相关
      • 音视频质量
      • 其他
RTC Engine
当前内容仅提供英语版本,中文版我们将尽快补充,感谢您的理解。

处理自动播放受限

Introduction

In order to prevent web pages from automatically playing audio and video and causing interference to users, browsers have restricted the automatic playback function of audio and video: before the user interacts with the web page (such as clicking, touching the page, etc.), the web page will be prohibited from playing media with sound. In iOS 10+, if low power mode is enabled, media without sound will also be prohibited from playing.

Affected by the above browser autoplay policy, users may not be able to hear the sound when playing audio. The most common business scenario for this issue is that the users are able to enter the room and start remote audio automatically without user interaction(e.g. click) after refreshing the page.

This tutorial mainly introduces how to solve the issue of playback failure caused by the restriction of autoplay policy.

Solutions

1. Use the SDK's autoplay popup window

By default, when autoplay fails, the SDK will pop up to guide the user to interact with the page. After the interaction occurs, the SDK will actively call the interface to resume playback.
Advantage: The business side does not need to do anything, simple and efficient.
Disadvantage: The popup window provided by the SDK may not meet the design requirements of the business product. At this time, you can consider using Solution 2.
The popup window provided by the SDK is adapted to desktop and mobile browser, and the style is as follows:





The SDK will switch the English and Chinese popup prompts according to the value of navigator.language.
When the user clicks "OK", the SDK automatically calls the relevant interface to resume playback.
In order to ensure that the popup window is displayed on the top layer as much as possible, its z-index value is 1500.

2. Business side provides popup window processing

If Solution 1 does not meet your product design requirements, you can also solve the autoplay problem in the following ways.

2.1 Setting the enableAutoPlayDialog parameter in the trtc.enterRoom interface to false to turn off the SDK's popup window.
2.2 Listening to the AUTOPLAY_FAILED event, and guiding the user to click the page when the event triggered. The SDK will automatically resume the audio playback after the user clicks the page.
2.3 In product design, it is recommended to guide users to interact with the page before entering the room (such as clicking the enter room button), which can avoid autoplay failure.
trtc.on(TRTC.EVENT.AUTOPLAY_FAILED, event => {
// Guide the user to click the page, you can pop up a prompt.
});
await trtc.enterRoom({ enableAutoPlayDialog: false });
Most browsers release the autoplay restriction after user interaction, and this step can effectively avoid the error of autoplay failure. However, due to the differences in the implementation of autoplay policies by various browser manufacturers, even if users are guided to interact with the page in advance, autoplay failure errors may still occur. Therefore, you still need to listen to the AUTOPLAY_FAILED event, and guiding the user to click the page.

For example: In the iOS WeChat browser and its mini-program webview, when playing a remote stream for the first time on the page, you must call the playback interface in the callback function of the user click event, otherwise playback will fail. If you use setTimeout and other interfaces to asynchronously call the playback interface in the callback of the user click event, you will also encounter autoplay failure errors.

Disable Autoplay Policy in Webview

The default autoplay policy in Android and iOS Webview may be different to the browser. You can refer to the following document to turn off autoplay restrictions in your App.

iOS Webview: Set mediaTypesRequiringUserActionForPlayback to WKAudiovisualMediaTypeNone.

Reference