TVODefaultAudioDevice Class Reference

Inherits from NSObject
Conforms to TVOAudioDevice
Declared in TVODefaultAudioDevice.h

Overview

TVODefaultAudioDevice allows you to record and playback audio when you are connected to a Call.

  block

A block to configure the AVAudiosession.

@property (nonatomic, copy, nonnull) TVOAVAudioSessionConfigurationBlock block

Discussion

If TVODefaultAudioDevice is enabled, the SDK executes this block and activates the audio session while connecting to a Call, otherwise it is the developer’s responsibility to execute the block. Please note that the getter of this property returns a wrapper block which internally executes the block you set. By default, the SDK returns a default wrapper block which executes kTVODefaultAVAudioSessionConfigurationBlock internally.

The following example demonstrates changing the audio route from speaker to receiver:

  TVODefaultAudioDevice *audioDevice = [TVODefaultAudioDevice audioDevice];

  TwilioVoice.audioDevice = audioDevice;

  //...connect to a Call with audioDevice. By default the audio route will be configured to receiver.

  audioDevice.block =  ^ {
      // We will execute `kTVODefaultAVAudioSessionConfigurationBlock` first.
      kTVODefaultAVAudioSessionConfigurationBlock();

      // Overwrite the audio route
      AVAudioSession *session = [AVAudioSession sharedInstance];
      NSError *error = nil;
      if (![session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error]) {
          NSLog(@"AVAudiosession overrideOutputAudioPort %@",error);
      }
  };
  audioDevice.block();

Declared In

TVODefaultAudioDevice.h

  enabled

A boolean which enables playback and recording.

@property (nonatomic, assign, getter=isEnabled) BOOL enabled

Discussion

By default, the SDK initializes this property to YES. Setting it to NO forces the underlying CoreAudio graph to be stopped (if active), and prevents it from being started again. Setting the property to YES allows the audio graph to be started whenever there is audio to play or record in a Call.

Declared In

TVODefaultAudioDevice.h

– init

Developers shouldn’t initialize this class directly.

- (null_unspecified instancetype)init

Discussion

Use defaultAudioDeviceto create a TVODefaultAudioDevice.

Declared In

TVODefaultAudioDevice.h

+ audioDevice

Factory method to create an instance of TVODefaultAudioDevice.

+ (nonnull instancetype)audioDevice

Declared In

TVODefaultAudioDevice.h

+ audioDeviceWithBlock:

Factory method with a block to create an instance of TVODefaultAudioDevice.

+ (nonnull instancetype)audioDeviceWithBlock:(TVOAVAudioSessionConfigurationBlock _Nonnull)block

Parameters

block

The AVAudioSession configuration block.

Return Value

An instance of TVODefaultAudioDevice.

Discussion

Use this factory method if you want to connect to a Call with your choice of audio session configuration.

The following example demonstrates connecting to a Call using the AVAudioSessionCategoryPlayback category:

  TwilioVoice.audioDevice = [TVODefaultAudioDevice audioDeviceWithBlock:^ {
      // We will execute `kTVODefaultAVAudioSessionConfigurationBlock` first.
      kTVODefaultAVAudioSessionConfigurationBlock();

      // Overwrite the category to `playback`
      AVAudioSession *session = [AVAudioSession sharedInstance];
      NSError *error = nil;
      if (![session setCategory:AVAudioSessionCategoryPlayback
                           mode:AVAudioSessionModeVoiceChat
                        options:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP
                          error:&error]) {
          NSLog(@"AVAudioSession setCategory:options:mode:error: %@",error);
      }
  }];

  TVOConnectOptions *connectOptions = [TVOConnectOptions optionsWithToken:token
                                                                    block:^(TVOConnectOptionsBuilder *builder) {
      // configure builder attributes here
  }];

  TVOCall *call = [TwilioVoice connectWithOptions:connectOptions];

Declared In

TVODefaultAudioDevice.h