TVIDefaultAudioDevice Class Reference
Inherits from | NSObject |
---|---|
Conforms to | TVIAudioDevice |
Declared in | TVIDefaultAudioDevice.h |
Overview
TVIDefaultAudioDevice
allows you to record and playback audio when you are connected to a Room.
block
A block to configure the AVAudiosession.
@property (nonatomic, copy, nonnull) TVIAVAudioSessionConfigurationBlock block
Discussion
If TVIDefaultAudioDevice
is enabled
, the SDK executes this block and activates the audio session while
connecting to a Room, 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 kDefaultAVAudioSessionConfigurationBlock
internally.
The following example demonstrates changing the audio route from speaker to receiver:
TVIDefaultAudioDevice *audioDevice = [TVIDefaultAudioDevice audioDevice];
TwilioVideo.audioDevice = audioDevice;
//...connect to a Room with audioDevice. By default the audio route will be configured to speaker.
audioDevice.block = ^ {
// We will execute `kDefaultAVAudioSessionConfigurationBlock` first.
kDefaultAVAudioSessionConfigurationBlock();
// Overwrite the audio route
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *error = nil;
if (![session setMode:AVAudioSessionModeVoiceChat error:&error]) {
NSLog(@"AVAudiosession setMode %@",error);
}
if (![session overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&error]) {
NSLog(@"AVAudiosession overrideOutputAudioPort %@",error);
}
};
audioDevice.block();
Declared In
TVIDefaultAudioDevice.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 Room.
Declared In
TVIDefaultAudioDevice.h
– init
Developers shouldn’t initialize this class directly.
- (null_unspecified instancetype)init
Discussion
Use defaultAudioDevice
to create a TVIDefaultAudioDevice
.
Declared In
TVIDefaultAudioDevice.h
+ audioDevice
Factory method to create an instance of TVIDefaultAudioDevice
.
+ (nonnull instancetype)audioDevice
Declared In
TVIDefaultAudioDevice.h
+ audioDeviceWithBlock:
Factory method with a block to create an instance of TVIDefaultAudioDevice
.
+ (nonnull instancetype)audioDeviceWithBlock:(TVIAVAudioSessionConfigurationBlock _Nonnull)block
Parameters
block |
The AVAudioSession configuration block. |
---|
Return Value
An instance of TVIDefaultAudioDevice.
Discussion
Use this factory method if you want to connect to a Room with your choice of audio session configuration.
The following example demonstrates connecting to a Room using the AVAudioSessionCategoryPlayback category:
TwilioVideo.audioDevice = [TVIDefaultAudioDevice audioDeviceWithBlock:^ {
// We will execute `kDefaultAVAudioSessionConfigurationBlock` first.
kDefaultAVAudioSessionConfigurationBlock();
// Overwrite the category to `playback`
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *error = nil;
if (![session setCategory:AVAudioSessionCategoryPlayback
mode:AVAudioSessionModeVideoChat
options:AVAudioSessionCategoryOptionAllowBluetooth
error:&error]) {
NSLog(@"AVAudioSession setCategory:options:mode:error: %@",error);
}
}];
TVIConnectOptions *connectOptions = [TVIConnectOptions optionsWithToken:token
block:^(TVIConnectOptionsBuilder *builder) {
builder.audioTracks = @[[TVILocalAudioTrack track]];
}];
TVIRoom *room = [TwilioVideo connectWithOptions:connectOptions];
Declared In
TVIDefaultAudioDevice.h