当用户在 RTC 与白板的动态 PPT 同时使用时,可能会遇到以下问题:
为了解决这些问题,2.9.15 的白板内置了用于混音的 RTC 接口,用户在根据本章内容进行实现后可以避免这些问题。
如果用户使用的 RTC 提供商不支持混音本章内容将会无效
样例代码可以参考 Whiteboard-iOS rtc 分支,RTC 文件夹内容
本文中 RTC 使用 Agora SDK 作为实例,运行 demo 前请先在
AppID.swift
中配置好 AppId
WhiteAudioMixerBridgeDelegate
协议。WhiteSDK
时,传入实现audioMixerBridgeDelegate
协议的对象。rtcEngine:localAudioMixingStateDidChanged:errorCode:
回调中,主动调用 WhiteSDK
的audioMixer
属性中setMediaState:errorCode:
方法,告知音视频状态更新完成。当白板动态 ppt 进行播放时,会在准备播放时,主动调用 startAudioMixing:filePath:loopback:replace:cycle
API,开发者需要在此处主动调用 RTC sdk 的混音接口。
在 iOS sdk 中存在一种情况:当该方法失败时,rtc SDK 不会主动调用
rtcEngine:localAudioMixingStateDidChanged:errorCode:
所以,无法当该值为非 0 数值时,开发者需要直接在此处代码直接调用audioMixer
的setMediaState:errorCode:
方法进行传递,将非零返回值传入 errorCode,stateCode 随意填写即可。
extension VideoChatViewController: WhiteAudioMixerBridgeDelegate {
func startAudioMixing(_ filePath: String, loopback: Bool, replace: Bool, cycle: Int) {
// 现阶段 iOS 端 rtc 不支持对线上 mp4 文件进行混音。该类文件混音,会出现跳转失败导致混音效果消失的问题。
// 如果是 线上 mp4 地址,请提前使用 动态 ppt 资源包下载
// 该 filePath 路径会收到初始化 SDK 时,pptParams 中的 scheme 参数影响。请自行恢复。
let result:Int32 = agoraKit.startAudioMixing(filePath, loopback: true, replace: false, cycle: 1)
print("\(#function) \(filePath) \(loopback) \(replace) \(cycle) result:\(result)")
if result != 0 {
self.whiteSdk!.audioMixer?.setMediaState(714, errorCode: Int(result))
}
}
func stopAudioMixing() {
let result:Int32 = agoraKit.stopAudioMixing()
print("\(#function) result:\(result)")
if result != 0 {
self.whiteSdk!.audioMixer?.setMediaState(0, errorCode: Int(result))
}
}
func setAudioMixingPosition(_ position: Int) {
print("position: \(position)")
let result: Int32 = agoraKit.setAudioMixingPosition(position)
print("\(#function) result:\(result) position: \(position)")
if result != 0 {
self.whiteSdk!.audioMixer?.setMediaState(0, errorCode: Int(result))
}
}
}
extension VideoChatViewController: AgoraRtcEngineDelegate {
...
func rtcEngine(_ engine: AgoraRtcEngineKit, localAudioMixingStateDidChanged state: AgoraAudioMixingStateCode, errorCode: AgoraAudioMixingErrorCode) {
print("localAudioMixingStateDidChanged: \(state.rawValue) errorCode: \(errorCode.rawValue)")
if let sdk = self.whiteSdk {
sdk.audioMixer?.setMediaState(state.rawValue, errorCode: errorCode.rawValue)
} else {
print("sdk not init !")
}
}
...
}
以上内容,可在VideoChatViewController.swift
项目中进行查看。