Class

WKAudioFilePlayer

An object that controls playback of a single audio item.

Overview

Use a player object to start and stop playback and to control the rate of playback. (The WKAudioFileQueuePlayer subclass extends the basic behavior to support playback of more than one item.)

The value of the player’s presentation-related properties are not valid until the underlying asset is loaded. Use the value of the status property to determine when it is valid to get the values of other properties. Specifically, wait until the status changes to readyToPlay to access relevant properties.

The WKAudioFilePlayer class is key-value observing compliant for the currentItem, status, and rate properties. You can use an observer to detect changes to those properties and react accordingly. For information on how to observe properties using key-value observing, see Key-Value Observing Programming Guide.

Topics

Creating a Player

init(playerItem: WKAudioFilePlayerItem)

Creates and returns a player initialized with the specified player item.

func replaceCurrentItem(with: WKAudioFilePlayerItem?)

Replaces the current player item with a different one.

Configuring and Controlling Playback

func play()

Begins playback of the current item.

func pause()

Pauses playback of the associated item.

var rate: Float

The current rate of playback.

Getting Information About the Player

var currentItem: WKAudioFilePlayerItem?

The player’s current item.

var status: WKAudioFilePlayerStatus

The status of the player.

var error: Error?

An error that describes the cause of a failure.

Getting Timing Information

var currentTime: TimeInterval

The elapsed time for the current playing item.

Constants

enum WKAudioFilePlayerStatus

Constants that represent the status of the player.

Relationships

Inherits From

Conforms To

See Also

Audio

class WKAudioFileQueuePlayer

An object that controls playback of one or more audio items.

class WKAudioFilePlayerItem

An object that manages the presentation state of an audio file while it is being played.

class WKAudioFileAsset

An object that stores a reference to an audio file and provides metadata information about that file.