Playback commands
Declare the playback controls your app supports.
Overview
Use MediaCommand to define the controls available for your Now Playing session. The system displays these controls on the Lock Screen, Control Center, and connected accessories. Each command takes an action closure that the system invokes when someone interacts with a control.
Return an array of commands from your commands property. Create each command with a static factory method on MediaCommand:
var commands: [MediaCommand] {
[
.play { self.play() },
.pause { self.pause() },
.next { self.next() }.enabled(hasNextTrack),
.previous { self.previous() }.enabled(hasPreviousTrack),
.seekToPosition { time in
self.seek(to: time)
},
]
}Use enabled(_:) to make a command available or unavailable based on your app’s state. Unavailable commands still appear in the interface, but the system doesn’t invoke their handler.
Topics
Creating commands
Controlling playback
Navigating commands
Seeking
Changing playback modes
changePlaybackRate(supported:_:)changeRepeatMode(current:supported:_:)changeShuffleMode(current:supported:_:)MediaCommand.RepeatModeMediaCommand.ShuffleMode