MediaSessionRepresentable
protocol · iOS 27.0+ · SDK 27.1
@MainActor protocol MediaSessionRepresentable : IdentifiableA protocol that provides content metadata, playback state, and commands for a Now Playing session. Conform to this protocol to provide the media content description, playback state, and commands like ``MediaCommand/play(_:)``, ``MediaCommand/pause(_:)``, ``MediaCommand/next(_:)``, ``MediaCommand/previous(_:)``, and more. The framework observes your `@Observable` model and automatically updates the system's Now Playing interface when your properties change. For more information, see <doc:publishing-media-sessions> The following example shows a basic session representable: ```swift @Observable class PlayerModel: MediaSessionRepresentable { let id = "com.example.music" var currentTrack: Track? var isPlaying = false var currentTime: TimeInterval = 0 var content: (any MediaContentRepresentable)? { guard let track = currentTrack else { return nil } return MusicContent( id: track.id, songTitle: track.title, artistName: track.artist, albumName: track.album, type: .audio, duration: .finite(track.duration), isExplicit: track.isExplicit, artwork: Artwork(id: track.artworkID) { size in let data = await self.loadArtworkData(with: size) return try ArtworkRepresentation(data: data) } ) } var playbackSnapshot: MediaPlaybackSnapshot? { if isPlaying { return MediaPlaybackSnapshot(state: .playing(rate: 1.0), elapsedTime: currentTime, timestamp: .now) } else { return MediaPlaybackSnapshot(state: .paused, elapsedTime: currentTime, timestamp: .now) } } var commands: [MediaCommand] {[ .play { await self.play() }, .pause { await self.pause() }, .next { await self.nextTrack() }, .previous { await self.previousTrack() }, ]} } ```
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
No declarations were skipped in this snapshot.