SINAudioController

Objective-C

@protocol SINAudioController <NSObject>

Swift

protocol SINAudioController : NSObjectProtocol

The SINAudioController provides methods for controlling audio related functionality, e.g. enabling the speaker, muting the microphone, and playing sound files.

Playing Sound Files

The audio controller provides a convenience method (startPlayingSoundFile:loop:) for playing sounds that are related to a call, such as ringtones and busy tones.

  • Example:
    id<SINAudioController> audio = [client audioController];
    NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"ringtone" ofType:@"wav"];

    [audio startPlayingSoundFile:soundPath loop:YES];

Applications that prefer to use their own code for playing sounds are free to do so, but they should follow a few guidelines related to audio session categories and audio session activation/deactivation (see Sinch SDK User Guide for details).

Sound File Format

The sound file must be a mono (1 channel), 16-bit, uncompressed (PCM) .wav file with a sample rate of 8kHz, 16kHz, or 32kHz.

  • The object that acts as the delegate of the audio controller.

    The delegate object handles audio related state changes.

    Declaration

    Objective-C

    @property (nonatomic, weak, readwrite) id<SINAudioControllerDelegate> delegate;

    Swift

    weak var delegate: SINAudioControllerDelegate! { get set }
  • Mute the microphone.

    Declaration

    Objective-C

    - (void)mute;

    Swift

    func mute()
  • Unmute the microphone.

    Declaration

    Objective-C

    - (void)unmute;

    Swift

    func unmute()
  • Route the call audio through the speaker.

    Changing the audio route for a call is only possible when the call has been established.

    See

    SINCallStateEstablished

    Declaration

    Objective-C

    - (void)enableSpeaker;

    Swift

    func enableSpeaker()
  • Route the call audio through the handset earpiece.

    Changing the audio route for a call is only possible when the call has been established.

    See

    SINCallStateEstablished

    Declaration

    Objective-C

    - (void)disableSpeaker;

    Swift

    func disableSpeaker()
  • Play a sound file, for the purpose of playing ringtones, etc.

    This is a simple convenience method for playing sounds associated with a call, such as ringtones. It can only play one sound file at a time.

    For advanced audio, apps that use the SDK should implement their own methods for playing sounds.

    Regardless of whether a sound is looping or not, a corresponding call to the stopPlayingSoundFile method must be done at some point after each invocation of this method.

    The sound file must be a mono (1 channel), 16-bit, uncompressed (PCM) .wav file with a sample rate of 8kHz, 16kHz, or 32kHz.

    Throws

    NSInvalidArgumentException if no file exists at the given path.

    Declaration

    Objective-C

    - (void)startPlayingSoundFile:(NSString *)path loop:(BOOL)loop;

    Swift

    func startPlayingSoundFile(_ path: String!, loop: Bool)

    Parameters

    path

    Full path for the sound file to play.

    loop

    Specifies whether the sound should loop or not.

  • Stop playing the sound file.

    Declaration

    Objective-C

    - (void)stopPlayingSoundFile;

    Swift

    func stopPlayingSoundFile()
  • Configure the audio session for an incoming CallKit call.

    Important

    This method should be invoked before the CXAnswerCallAction is fulfilled.

    Declaration

    Objective-C

    - (void)configureAudioSessionForCallKitCall;

    Swift

    func configureAudioSessionForCallKitCall()