---
title: MediaSessionRepresentable
framework: nowplaying
role: symbol
role_heading: Protocol
path: nowplaying/mediasessionrepresentable
---

# MediaSessionRepresentable

A protocol that provides content metadata, playback state, and commands for a Now Playing session.

## Declaration

```swift
@MainActor protocol MediaSessionRepresentable : Identifiable
```

## Mentioned in

Publishing media sessions

## Overview

Overview Conform to this protocol to provide the media content description, playback state, and commands like play(_:), pause(_:), next(_:), previous(_:), and more. The framework observes your @Observable model and automatically updates the system’s Now Playing interface when your properties change. The following example shows a basic session representable: @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() },     ]} }

## Topics

### Instance Properties

- [commands](nowplaying/mediasessionrepresentable/commands.md)
- [content](nowplaying/mediasessionrepresentable/content.md)
- [id](nowplaying/mediasessionrepresentable/id.md)
- [playbackSnapshot](nowplaying/mediasessionrepresentable/playbacksnapshot.md)

## Relationships

### Inherits From

- [Identifiable](swift/identifiable.md)

## See Also

### Local sessions

- [Publishing media sessions](nowplaying/publishing-media-sessions.md)
- [MediaSession](nowplaying/mediasession.md)
- [MediaSessionError](nowplaying/mediasessionerror.md)
