@afkcodes/timbre-media-session
Classes
| Class | Description |
|---|---|
| BaseMediaHandler | No-op implementation of every MediaHandler method. |
| BrowseError | Throw this (or reject with it) from any browse method to put the car's sign-in / upgrade screen on screen instead of an empty list. |
| CompositeMediaHandler | Delegating base for handler decorators — analytics, persistence, logging. |
| MediaSessionError | - |
Interfaces
| Interface | Description |
|---|---|
| AndroidMediaSessionConfig | Android half of MediaSessionConfig. Ignored on iOS. |
| BrowseItem | One node of the car browse tree. |
| IosMediaSessionConfig | iOS half of MediaSessionConfig. Ignored on Android. |
| MediaCustomAction | A custom action: a button with no built-in meaning. |
| MediaHandler | The fan-in interface. Every remote surface — notification, lock screen, Bluetooth, headset, watch, Android Auto, Control Center, and the app's own UI — arrives here. |
| MediaServiceApi | The broadcast + lifecycle surface returned by MediaService.init. |
| MediaServiceConfig | Configuration accepted by MediaService.init. |
| MediaServiceController | MediaServiceApi plus the one-time wiring call. |
| MediaSessionConfig | Both platform halves optional — supply only the platform you care about. The cross-platform options sit at the top level. |
| MediaSessionHandlers | The fan-in surface: one callback per remote command, supplied once at RnMediaMediaSession.initialize. |
| MediaSessionStorage | Where a persisted session is written. Injected, structurally typed, and never depended on — exactly the shape AsyncStorage, react-native-mmkv, expo-sqlite/kv-store and a five-line in-memory map all already satisfy. |
| NativeMediaItem | Metadata for the item currently playing. |
| NativePlaybackState | Everything a surface needs to render "now", except the metadata. |
| NativeRemotePlayback | "Playback is coming out of some other device right now, and here is that device's volume." See RnMediaMediaSession.setRemotePlayback. |
| NativeSleepTimerState | What the sleep timer is doing right now. |
| PersistedMediaService | MediaServiceApi plus the two hooks persistence needs. |
| PersistedSession | The three broadcast channels as they were last seen, plus when. |
| PersistenceAutosaveOptions | See PersistenceOptions.autosave. |
| PersistenceOptions | - |
| PlaybackState | The broadcast playback state, as the app writes it. |
| PositionAnchor | The position anchor. The single most important type in this package. |
| QueueBroadcaster | The one thing a queue-owning handler needs from the service: a way to push the queue out on broadcast channel 3. |
| QueueHandlerMethods | The surface withQueueHandling adds on top of a MediaHandler. |
| QueueHandlerOptions | - |
| RemotePlayback | "Playback is coming out of another device right now, and here is that device's volume." |
| RnMediaMediaSession | The process-wide media session. |
| SearchFocus | What a voice query was about, when the assistant could classify it. |
| SessionError | Something the session could not do, delivered to MediaHandler.onSessionError. |
Type Aliases
| Type Alias | Description |
|---|---|
| BrowseErrorCode | Why a browse request could not be answered. |
| BrowseMediaType | The semantic type of a browse node. See BrowseItem.mediaType. |
| BrowseStyle | How a browsable item's children render. See BrowseItem.childStyle. |
| CarConnection | Where playback is being controlled from. See MediaServiceApi.getCarConnection. |
| MediaCapability | A capability the app is willing to service, independent of whether it wants a button for it. |
| MediaControl | A button the app wants offered on remote surfaces. |
| MediaItem | Metadata for one playable thing. |
| MediaPlaybackStatus | Coarse playback status, broadcast by the app. |
| MediaRepeatMode | Repeat mode as every remote surface understands it. |
| MediaSessionErrorCode | Why a media-session call was rejected. |
| QueueHandler | Instance type of QueueHandler. |
| RemoteVolumeControl | How much of the remote device's volume the backend can actually drive. |
| RemoteVolumeDirection | Which way a hardware volume key moved. See MediaHandler.onAdjustDeviceVolume. |
| RestoreResult | What restorePersisted found. A typed result, never a throw: a corrupt record is an ordinary runtime condition (a half-written file, an app downgrade, a user clearing storage), and an app that has to try/catch its cold start will eventually not. |
| SessionErrorCode | Something the session could not do, on a channel the app can actually read. |
| SessionErrorSeverity | How much a SessionError took away. |
| SleepTimerMode | Which shape of sleep timer is armed. See RnMediaMediaSession.getSleepTimer. |
| SleepTimerState | What the native sleep timer is doing, as MediaServiceApi.getSleepTimer reports it. |
Variables
| Variable | Description |
|---|---|
| BROWSE_ROOT | The id the car asks for when it wants the root tabs. |
| DEFAULT_AUTOSAVE_INTERVAL_MS | The default PersistenceAutosaveOptions.intervalMs: 30 seconds. |
| DEFAULT_JUMP_SECONDS | The one jump interval, in seconds, applied identically on both platforms. |
| DEFAULT_PERSISTENCE_KEY | Default storage key. Namespaced so it cannot collide with the app's own. |
| DEFAULT_PLAYBACK_RESUMPTION | Playback resumption is off unless the app asks for it. |
| DEFAULT_REMOTE_VOLUME_CONTROL | What a remote backend is assumed able to do with its volume. |
| DEFAULT_REMOTE_VOLUME_STEPS | Notches a hardware volume key press moves through when the app says nothing. |
| DEFAULT_REPEAT_MODE | What every surface showed before repeatMode existed. |
| DEFAULT_SHUFFLE_ENABLED | What every surface showed before shuffleEnabled existed. |
| DEFAULT_STOP_FOREGROUND_ON_PAUSE | stopForegroundOnPause follows audio_service's default. See PLAN §5.6. |
| DEFAULT_SUPPORTED_PLAYBACK_RATES | MPChangePlaybackRateCommand.supportedPlaybackRates when the app names none. |
| MAX_COMPACT_CONTROLS | Android's collapsed media notification has three action slots. media3 will silently drop the overflow; we would rather the app hear about it. |
| MAX_ROOT_TABS | How many tabs the root may have. |
| MAX_STOP_FOREGROUND_TIMEOUT_MS | media3's MediaSessionService.DEFAULT_FOREGROUND_SERVICE_TIMEOUT_MS, which is both the default and the maximum: the setter runs the argument through Util.constrainValue(v, 0, DEFAULT_FOREGROUND_SERVICE_TIMEOUT_MS), so a larger value is clamped down rather than honoured (media3 1.11.0, confirmed by javap on the shipped AAR: ConstantValue: long 600000l). |
| MediaService | The process-wide media session. |
| MIN_AUTOSAVE_INTERVAL_MS | The floor under PersistenceAutosaveOptions.intervalMs: 1 second. |
| PERSISTENCE_SCHEMA_VERSION | Version stamped into every record and required on the way back in. |
| QueueHandler | withQueueHandling applied to BaseMediaHandler — the class an app extends when it has no other base. |
| SESSION_ERROR_SEVERITY | The one place a SessionErrorCode is graded. |
Functions
| Function | Description |
|---|---|
| applyPersisted | Broadcast a restored session, in the order the channels expect. |
| capRootTabs | Enforce the two rules every car's root has, in one place for both platforms. |
| clearPersisted | Forget the persisted session. |
| createMediaService | Build a media service over a native hybrid object. |
| isBrowseError | Structural BrowseError test — see BrowseError.name. |
| logSessionError | Where a SessionError goes when the app has nowhere for it. |
| normalizeConfig | - |
| normalizePlaybackState | Validate and fill in a PlaybackState, producing the exact struct the bridge wants. The single choke point: nothing reaches native un-validated. |
| normalizeRemotePlayback | Validate and fill in a RemotePlayback. |
| restorePersisted | Read back whatever withPersistence last wrote. |
| stepRemoteVolume | The volume one hardware key press lands on, as a normalised 0..1 level. |
| toSessionError | Build the SessionError the app sees from what the bridge delivered. |
| useCarConnection | Whether a car is driving this session, and which kind — re-rendering on every transition. |
| validateAnchor | The anchor is the one payload whose garbage is invisible until a user stares at a lock screen counting backwards, so it is validated hardest. |
| validateMediaItem | - |
| validateQueue | - |
| validateSleepTimerSeconds | Validate a sleep-timer duration. |
| withPersistence | Tee the three broadcast channels into storage, so a session survives process death. |
| withQueueHandling | Give a handler default queue navigation over the data it broadcasts on channel 3. |