How to disable audio in webrtc mobile app(ios) without changing in framework

佐手、 提交于 2019-12-24 09:27:31

问题


I am working with webrtc mobile(ios). I can't disable audio in webrtc(ios). I have got no flag to disable audio.By changing in framwork/library it can done easily. My purpose is that I have to disable audio without changing in framework/library. Can anyone help me?.


回答1:


Update your question with code snippet, how you are creating mediaStrem or tracks(audio/video).

Generally with default Native WebRTC Framework,

RTCMediaStream localStream = [_factory mediaStreamWithStreamId:kARDMediaStreamId];
if(audioRequired) {
  RTCAudioTrack *aTrack = [_lmStream createLocalAudioTrack];
  [localStream addAudioTrack:aTrack];
}
RTCVideoTrack *vTrack = [_lmStream createLocalVideoTrack];
[localStream addVideoTrack:vTrack];
[_peerConnection addStream:localStream];

If you want to mute the Audio during the call, use below function.

- (void)enableAudio:(NSString *)id isAudioEnabled:(BOOL) isAudioEnabled {
  NSLog(@"Auido enabled: %d streams count:%d ", id, isAudioEnabled, _peerConnection.localStreams.count);
  if(_peerConnection.localStreams.count > 0) {
    RTCMediaStream *lStream = _peerConnection.localStreams[0];
    if(lStream.audioTracks.count > 0) { // Usually we will have only one track. If you have more than one, need to traverse all.
      // isAudioEnabled == 1 -> Unmute
      // isAudioEnabled == 0 -> Mute
      [lStream.audioTracks[0] setIsEnabled:isAudioEnabled];
    }
  }
}


来源:https://stackoverflow.com/questions/44131447/how-to-disable-audio-in-webrtc-mobile-appios-without-changing-in-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!