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


class WKAudioFilePlayerItem : NSObject


Create a player item for each WKAudioFileAsset object you want to play and use the player item to observe the state of the audio during playback. You can then associate the player item with an audio queue or player object to control the playback.

The value of the player item’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 WKAudioFilePlayerItemStatus.readyToPlay to access relevant properties.

If you want to play an asset more than once within a queue of items, you must create separate player items for each placement in the queue.


Creating a Player Item

init(asset: WKAudioFileAsset)

Creates and returns a player item for the specified audio file asset.

Getting Information About the Item

var asset: WKAudioFileAsset

The audio file asset being managed.

var status: WKAudioFilePlayerItemStatus

The status of the player item.

var error: Error?

An error that describes the cause of a failure.

Managing the Playback Position

var currentTime: TimeInterval

The current playback point, measured in seconds, from the beginning of the audio file.

func setCurrentTime(TimeInterval)

Sets the playback point, measured in seconds, from the beginning of the audio file.

Accessing the Item’s Status

enum WKAudioFilePlayerItemStatus

Constants that represent the status of a player item.

Receiving Notifications

static let WKAudioFilePlayerItemTimeJumped: NSNotification.Name

A notification that the item’s current time has changed discontinuously.

static let WKAudioFilePlayerItemDidPlayToEndTime: NSNotification.Name

A notification that the item has played successfully to its end.

static let WKAudioFilePlayerItemFailedToPlayToEndTime: NSNotification.Name

A notification that the item failed to play to its end.


Inherits From

Conforms To

See Also


Playing Background Audio

Enable background audio in your app to provide a seamless playback experience.

Adding a Now Playing View

Provide a view that controls the currently playing audio from your app.

class WKInterfaceVolumeControl

An interface element that lets users control the audio volume from the watch or a paired iPhone.

property list key PUICAutoLaunchAudioOptOut

A Boolean value indicating whether a watchOS app should opt out of automatically launching when its companion iOS app starts playing audio content.

Name: Opt out of Auto-launch Audio App (Watch)
class WKAudioFilePlayer

An object that controls playback of a single audio item.

class WKAudioFileQueuePlayer

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

class WKAudioFileAsset

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