opentok-ios-sdk-samples-swift icon indicating copy to clipboard operation
opentok-ios-sdk-samples-swift copied to clipboard

How To Mute Subscriber Audio using Custom Audio Driver (Swift)

Open mehmetbaykar opened this issue 2 years ago • 1 comments

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)?

mehmetbaykar avatar Sep 17 '21 08:09 mehmetbaykar

  • same problem

InfiniteFalltrough avatar Nov 04 '21 08:11 InfiniteFalltrough

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];
}

v-kpheng avatar Nov 18 '22 17:11 v-kpheng