在WebRTC M80 发行说明中,他们声明他们将弃用移动库。
为了及时了解本地移动库(iOS 和 Android)的最新错误修复和功能,我们需要从源代码构建。
在我使用从源代码构建的 AppRTCMobile 示例应用程序后WebRTC.framework
,我进行了一些更改并验证我能够按需静音远程音轨。
在我为遥控器ARDAppClient.h
添加一个强RTCMediaStream
指针引用和一个用于切换流静音的方法头:
@property(nonatomic, strong) RTCMediaStream *remoteAudioStream;
// ...
- (void)setRemoteAudioEnabled:(BOOL)enabled;
在ARDAppClient.m
该RTCPeerConnectionDelegate
部分中,我听取didAddStream
委托并保存对远程流的引用:
- (void)peerConnection:(RTCPeerConnection *)peerConnection
didAddStream:(RTCMediaStream *)stream {
RTCLog(@"Stream with %lu video tracks and %lu audio tracks was added.",
(unsigned long)stream.videoTracks.count,
(unsigned long)stream.audioTracks.count);
_remoteAudioStream = stream;
}
在ARDAppClient.m
我还添加了一个函数来静音/取消静音我们现在引用的流:
- (void)setRemoteAudioEnabled:(BOOL)enabled {
if (_state == kARDAppClientStateDisconnected) {
return;
}
RTCLog(@"Setting remote stream to be %s", enabled ? "Enabled" : "Not Enabled");
RTCLog(@"Number of remote audio tracks = %lu", (unsigned long)_remoteAudioStream.audioTracks.count);
if (_remoteAudioStream.audioTracks.count == 0) {
RTCLog(@"ERROR no audio tracks to disable!");
return;
}
_remoteAudioTrack = _remoteAudioStream.audioTracks[0];
[_remoteAudioTrack setIsEnabled:enabled];
}
最后,在ARDVideoCallViewController.m
我覆盖切换相机按钮以切换远程音轨静音:
- (void)videoCallViewDidSwitchCamera:(ARDVideoCallView *)view {
// [_captureController switchCamera];
self.audioEnabled = !self.audioEnabled;
[_client setRemoteAudioEnabled:self.audioEnabled];
}