Fuchsia's Media Session Service mediates access between media players which choose to publish “media sessions” (from here on referred to as “sessions”) and other components of the system which want to observe or control those sessions, such as a “Now Playing” UI, a remote control, or a system media policy enforcer.
A system service, the media session registry service (here on, Registry Service), exposes two FIDL protocols: Publisher
and Discovery
.
Media players publish themselves over the Publisher
protocol. Clients interested in discovering ongoing media sessions on the system do so through the Discovery
protocol.
| Registry Service | |===============================|
Players ----> | Publisher | | | | | | Discovery | <---- “Now Playing” UI, etc |===============================|
A client can watch for updates to all sessions using Discovery.WatchSessions
.
let discovery_proxy = connect_to_service::<DiscoveryMarker>()?; let (session_watcher, session_watcher_request) = create_endpoints()?; let session_watcher_proxy = session_watcher.into_proxy()?; let watcher = discovery_proxy.watch_sessions( WatchOptions::default(), session_watcher_request)?; loop { let sessions_reply_future = session_watcher_proxy.watch_sessions()?; let sessions = await!(sessions_reply_future)?; for session in sessions { update_ui_for_session_with_id( session.id, session.player_status, session.media_images, session.metadata, ...); } }
Players must implement Player
and publish themselves once with Publisher.Publish
.
let (player_client_end, player_server_end) = create_endpoints()?; let publisher_proxy = connect_to_service::<PublisherMarker>()?; spawn_implementation_to_serve(player_server_end); publisher_proxy.publish(player_client_end, PlayerRegistration { domain: Some(PLAYER_DOMAIN), });