opentok-ios-sdk-samples-swift
opentok-ios-sdk-samples-swift copied to clipboard
How To Mute Subscriber Audio using Custom Audio Driver (Swift)
When doing a pretest call using Obj-c audio driver, I can mute the subscriber audio with
- (void)setAudioPlayoutMute:(BOOL)mute;
But when it comes to the Swift version of the custom audio driver there is no function that can mute the subscriber audio.
I can not set subscriber.subscribeToAudio = false
since I am doing a network test I should check video and audio package lost. So, How I can mute the subscriber audio using this custom driver(Swift)?
- same problem
Apologies for the belated reply.
This should work:
func setPlayoutVolume(_ value: Float32) {
if let recordingVoiceUnit = recordingVoiceUnit {
AudioUnitSetParameter(recordingVoiceUnit,
kMultiChannelMixerParam_Volume,
kAudioUnitScope_Input,
DefaultAudioDevice.kOutputBus,
value,
0
)
}
}
Alternatively, if you want to mute by not rendering audio frames, you can do the following :
// Add this logic here
// https://github.com/opentok/opentok-ios-sdk-samples-swift/blob/main/Custom-Audio-Driver/Custom-Audio-Driver/DefaultAudioDevice.swift#L569
if(muted) //set this on/off somewhere
{
[dev->_audioBus readRenderData:NULL numberOfSamples:0];
} else
{
[dev->_audioBus readRenderData:buffer_list->mBuffers[0].mData
numberOfSamples:num_frames];
}