> For a complete documentation index, fetch https://docs.voximplant.ai/llms.txt

# VIAudioFile

File player that plays local audio via `AVAudioPlayer`.

@objc final class VIAudioFile

Use this API for application sounds such as a ringtone or hold music. Supported file formats are: `.caf`, `.wav`, `.aiff`, `.aifc`, `.mp3`, and `.ac3`.

Outside a call or conference, playback configures the audio session with the `.playback` category. During a call or conference, playback reuses the existing `.playAndRecord` plus `.voiceChat` session.

Multiple [VIAudioFile](/api-reference/iossdk/core/viaudiofile) instances can play at the same time.

## Initializers

### init(data:)

@objc convenience init(data: Data) throws

Creates an audio file player from in-memory audio data.

**Parameters**

**data** Data

Audio file contents.

**Throws**

[VIAudioFileError](/api-reference/iossdk/core/viaudiofileerror) with [VIAudioFileErrorType.failedToInitialize](/api-reference/iossdk/core/viaudiofileerrortype#symbol-748a29a837bd3b1e) if the player cannot be created.

### init(url:)

@objc convenience init(url: URL) throws

Creates an audio file player from a local file URL.

**Parameters**

**url** URL

Local file URL of the audio resource.

**Throws**

[VIAudioFileError](/api-reference/iossdk/core/viaudiofileerror) with [VIAudioFileErrorType.failedToInitialize](/api-reference/iossdk/core/viaudiofileerrortype#symbol-748a29a837bd3b1e) if the player cannot be created.

## Properties

### delegate

@objc weak var delegate: [VIAudioFileDelegate](/api-reference/iossdk/core/viaudiofiledelegate)?

Object that conforms to the [VIAudioFileDelegate](/api-reference/iossdk/core/viaudiofiledelegate) protocol to receive playback events.

### isPlaying

@objc var isPlaying: Bool \{ get }

Whether the audio file is currently playing.

### url

@objc var url: URL? \{ get }

File URL used to create this player, or `nil` if the player was created from data.

## Methods

### pause()

@objc func pause()

Pauses playback and reports [audioFile(\_:didStopPlaying:)](/api-reference/iossdk/core/viaudiofiledelegate#symbol-cdb3cad399a0fb0d) with a `nil` error.

Has no effect if the file is not playing.

### play()

@objc func play()

Starts playback once from the current position.

Reports the result via [audioFile(\_:didStartPlaying:)](/api-reference/iossdk/core/viaudiofiledelegate#symbol-b169f45b01df2a07). If the file is already playing, reports [VIAudioFileErrorType.alreadyPlaying](/api-reference/iossdk/core/viaudiofileerrortype#symbol-a0f1c767c1a3a626).

### playLooped()

@objc func playLooped()

Starts looped playback from the current position.

Reports the result via [audioFile(\_:didStartPlaying:)](/api-reference/iossdk/core/viaudiofiledelegate#symbol-b169f45b01df2a07). If the file is already playing, reports [VIAudioFileErrorType.alreadyPlaying](/api-reference/iossdk/core/viaudiofileerrortype#symbol-a0f1c767c1a3a626).

### stop()

@objc func stop()

Stops playback, resets the position to the beginning, and reports [audioFile(\_:didStopPlaying:)](/api-reference/iossdk/core/viaudiofiledelegate#symbol-cdb3cad399a0fb0d) with a `nil` error.

Has no effect if the file is not playing.

## Relationships

**Inherits From:** NSObject

**Conforms To:** ObjectiveC.NSObjectProtocol, Swift.CVarArg, Swift.CustomDebugStringConvertible, Swift.CustomStringConvertible, Swift.Equatable, Swift.Hashable