VIAudioFile

A file player that automatically prepares audio session and plays sounds.

Supported file formats are: .caf, .wav, .aiff, .aifc, .mp3, .ac3

Limitations:

  • Playing audio file is not supported while there is an active connected call.
  • Playing audio file may be interrupted if audio within a call is started.
  • Playing audio file will be stopped if Siri or CallKit is activated.

Methods

initWithData:looped:

- (nullable instancetype)initWithData:(NSData *)audioFileData
                               looped:(BOOL)looped

Initialize audio file instance.

Parameters

  • audioFileData:

    NSData *

    Audio file Data.

  • looped:

    BOOL

    YES to play audio file repeatedly. NO to play once.

Returns

  • Return:

    nullable instancetype

    VIAudioFile instance or nil if audio file data is not valid or unsupported format is used.

initWithURL:looped:

- (nullable instancetype)initWithURL:(NSURL *)audioFileURL
                              looped:(BOOL)looped

Initialize audio file instance.

Parameters

  • audioFileURL:

    NSURL *

    Audio file URL.

  • looped:

    BOOL

    YES to play audio file repeatedly. NO to play once.

Returns

  • Return:

    nullable instancetype

    VIAudioFile instance or nil if url is not valid or unsupported format is used.

play

- (void)play

Start to play the audio file repeatedly or once based on [VIAudioFile looped] property.

If the audio file is already playing, calling this method will result in [VIAudioFileDelegate audioFile:didStartPlaying:] event with an error.

stop

- (void)stop

Stop playing of the audio file.

Calling this method has no effect if the audio file is not playing.

Properties

delegate

@property (nonatomic, weak, nullable) id<VIAudioFileDelegate> delegate

Delegate that handles events related to audio file playing process.

delegateQueue

@property (nonatomic, strong, nullable) dispatch_queue_t delegateQueue

All delegates methods will be called on this queue. Queue should be serial, but not concurrent (the main queue is applicable).

If not specified, the main queue will be used.

looped

@property (nonatomic, assign) BOOL looped

Indicates if the audio file should be played repeatedly or once.

url

@property (nonatomic, strong, readonly, nullable) NSURL *url

Audio file URL.