One Logo Pool Ball
MusicKit · IOS API REFERENCE

MusicPlayer

class · iOS 15.0+ · SDK 27.1

class MusicPlayer

An object your app uses to play music.

Members (14)

method · iOS 15.0+

endSeeking

TypeScript
endSeeking(): void
Swift declaration
func endSeeking()

Ends forward and backward seeking through the music content. Call this method to end a seek operation that begins when you call either the ``beginSeekingBackward()`` or ``beginSeekingForward()`` method. After calling this method, the player returns to its previous state. For example, if the entry is playing before seeking begins, it continues playing from the new playhead position after calling this method.

get · iOS 15.0+

playbackTime

TypeScript
get playbackTime(): number
Swift declaration
var playbackTime: TimeInterval { get set }

The current playback time, in seconds, of the current entry. Changing the value of this property moves the playhead to the new location. For content streaming live from a server, this value represents the time from the beginning of the playlist when it first loads. This property returns `NaN` if the <doc://com.apple.documentation/documentation/CoreMedia/CMTime> is invalid or indefinite.

set · iOS 15.0+

playbackTime

TypeScript
set playbackTime(value: number)
Swift declaration
var playbackTime: TimeInterval { get set }

The current playback time, in seconds, of the current entry. Changing the value of this property moves the playhead to the new location. For content streaming live from a server, this value represents the time from the beginning of the playlist when it first loads. This property returns `NaN` if the <doc://com.apple.documentation/documentation/CoreMedia/CMTime> is invalid or indefinite.

method · iOS 15.0+

prepareToPlay

TypeScript
prepareToPlay(): Promise<void>
Swift declaration
func prepareToPlay() async throws

Prepares the current queue for playback, interrupting any active (nonmixable) audio sessions. Call this function to ensure that the player buffers the starting entry in the queue and that the entry is ready to play.

method · iOS 15.0+

skipToNextEntry

TypeScript
skipToNextEntry(): Promise<void>
Swift declaration
func skipToNextEntry() async throws

Starts playback of the next entry in the playback queue. If the music player isn’t playing, this method designates the next entry as the next to play. When you call this method, playback ends if the music player is already at the last entry in the playback queue.

get · iOS 15.0+

isPreparedToPlay

TypeScript
get isPreparedToPlay(): boolean
Swift declaration
var isPreparedToPlay: Bool { get }

A Boolean value that indicates whether a music player is ready to play.

method · iOS 15.0+

beginSeekingForward

TypeScript
beginSeekingForward(): void
Swift declaration
func beginSeekingForward()

Begins seeking forward through the music content. Use this method to move the current playback position forward in time at an accelerated rate. Seeking begins when you call this method, and continues until you call the ``endSeeking()`` method. If the player is streaming the underlying content, this method has no effect.

method · iOS 15.0+

restartCurrentEntry

TypeScript
restartCurrentEntry(): void
Swift declaration
func restartCurrentEntry()

Restarts playback at the beginning of the currently playing entry.

method · iOS 15.0+

skipToPreviousEntry

TypeScript
skipToPreviousEntry(): Promise<void>
Swift declaration
func skipToPreviousEntry() async throws

Starts playback of the previous entry in the playback queue. If the music player isn’t playing, this method designates the previous entry as the next to play. When you call this method, playback ends if the music player is already at the first entry in the playback queue.

method · iOS 15.0+

beginSeekingBackward

TypeScript
beginSeekingBackward(): void
Swift declaration
func beginSeekingBackward()

Begins seeking backward through the music content. Use this method to move the current playback position backward in time at an accelerated rate. Seeking begins when you call this method, and continues until you call the ``endSeeking()`` method. If the player is streaming the underlying content, this method has no effect.

method · iOS 15.0+

play

TypeScript
play(): Promise<void>
Swift declaration
func play() async throws

Initiates playback from the current queue. If playback isn’t underway, this method resumes playback from its paused location; otherwise, this method plays the first available entry from the beginning. If a music player isn’t ready for playback when you call this method, this method prepares the music player and then starts playback.

method · iOS 15.0+

stop

TypeScript
stop(): void
Swift declaration
func stop()

Ends playback of the current entry.

method · iOS 15.0+

pause

TypeScript
pause(): void
Swift declaration
func pause()

Pauses playback of the current entry. If playback isn’t currently underway, this method has no effect. To resume playback of the current entry from the pause point, call the ``play()`` method.

get · iOS 15.0+

state

TypeScript
get state(): MusicPlayer_State
Swift declaration
final let state: MusicPlayer.State

An object that exposes the observable properties of the music player.

Skipped declarations

No declarations were skipped in this snapshot.

All MusicKit types →