MediaSession
A local Now Playing session that publishes metadata and commands to the system.
Declaration
@MainActor class MediaSession<Representable> where Representable : MediaSessionRepresentableMentioned in
Overview
Use a session to represent media playback happening on the current device. The session automatically observes your MediaSessionRepresentable model and syncs changes to the system’s Now Playing interface.
Create a session by providing a session representable:
let session = MediaSession(myModel)Call requestToBecomeApplicationPrimary() to make this your app’s primary Now Playing session when you want to display playback controls:
try await session.requestToBecomeApplicationPrimary()