RemoteMediaSession
A session that manages remote media playback across devices.
Declaration
@MainActor class RemoteMediaSession<Attributes> where Attributes : RemoteMediaSessionAttributesMentioned in
Overview
Use a remote session to represent media playback sessions happening outside of this device, but that your app wants to donate to the system so they may appear in the system’s Now Playing interface.
Use this API when your app has information about the remote session and wants to signal to the system that playback has started (using start(attributes:)) or something about the session has changed (using update(_:)).
You can also donate remote sessions to the system through push notifications, for example when playback starts while your app isn’t running.
In that case, use APNs to send a push notification to the user’s device that informs the system of a start, update, or end event.
The following example shows how to start a session:
struct MySessionAttributes: RemoteMediaSessionAttributes {
let id: String
let trackID: String
}
let attributes = MySessionAttributes(id: "session-123", trackID: "track-123")
let session = try await RemoteMediaSession.start(attributes: attributes)After starting a session, update its attributes or end it:
// Update the session attributes
try await session.update(newAttributes)
// End the session when playback completes
try await session.end()