Skip to main content

@afkcodes/timbre-media-session

Classes

ClassDescription
BaseMediaHandlerNo-op implementation of every MediaHandler method.
BrowseErrorThrow 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.
CompositeMediaHandlerDelegating base for handler decorators — analytics, persistence, logging.
MediaSessionError-

Interfaces

InterfaceDescription
AndroidMediaSessionConfigAndroid half of MediaSessionConfig. Ignored on iOS.
BrowseItemOne node of the car browse tree.
IosMediaSessionConfigiOS half of MediaSessionConfig. Ignored on Android.
MediaCustomActionA custom action: a button with no built-in meaning.
MediaHandlerThe fan-in interface. Every remote surface — notification, lock screen, Bluetooth, headset, watch, Android Auto, Control Center, and the app's own UI — arrives here.
MediaServiceApiThe broadcast + lifecycle surface returned by MediaService.init.
MediaServiceConfigConfiguration accepted by MediaService.init.
MediaServiceControllerMediaServiceApi plus the one-time wiring call.
MediaSessionConfigBoth platform halves optional — supply only the platform you care about. The cross-platform options sit at the top level.
MediaSessionHandlersThe fan-in surface: one callback per remote command, supplied once at RnMediaMediaSession.initialize.
MediaSessionStorageWhere 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.
NativeMediaItemMetadata for the item currently playing.
NativePlaybackStateEverything 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.
NativeSleepTimerStateWhat the sleep timer is doing right now.
PersistedMediaServiceMediaServiceApi plus the two hooks persistence needs.
PersistedSessionThe three broadcast channels as they were last seen, plus when.
PersistenceAutosaveOptionsSee PersistenceOptions.autosave.
PersistenceOptions-
PlaybackStateThe broadcast playback state, as the app writes it.
PositionAnchorThe position anchor. The single most important type in this package.
QueueBroadcasterThe one thing a queue-owning handler needs from the service: a way to push the queue out on broadcast channel 3.
QueueHandlerMethodsThe 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."
RnMediaMediaSessionThe process-wide media session.
SearchFocusWhat a voice query was about, when the assistant could classify it.
SessionErrorSomething the session could not do, delivered to MediaHandler.onSessionError.

Type Aliases

Type AliasDescription
BrowseErrorCodeWhy a browse request could not be answered.
BrowseMediaTypeThe semantic type of a browse node. See BrowseItem.mediaType.
BrowseStyleHow a browsable item's children render. See BrowseItem.childStyle.
CarConnectionWhere playback is being controlled from. See MediaServiceApi.getCarConnection.
MediaCapabilityA capability the app is willing to service, independent of whether it wants a button for it.
MediaControlA button the app wants offered on remote surfaces.
MediaItemMetadata for one playable thing.
MediaPlaybackStatusCoarse playback status, broadcast by the app.
MediaRepeatModeRepeat mode as every remote surface understands it.
MediaSessionErrorCodeWhy a media-session call was rejected.
QueueHandlerInstance type of QueueHandler.
RemoteVolumeControlHow much of the remote device's volume the backend can actually drive.
RemoteVolumeDirectionWhich way a hardware volume key moved. See MediaHandler.onAdjustDeviceVolume.
RestoreResultWhat 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.
SessionErrorCodeSomething the session could not do, on a channel the app can actually read.
SessionErrorSeverityHow much a SessionError took away.
SleepTimerModeWhich shape of sleep timer is armed. See RnMediaMediaSession.getSleepTimer.
SleepTimerStateWhat the native sleep timer is doing, as MediaServiceApi.getSleepTimer reports it.

Variables

VariableDescription
BROWSE_ROOTThe id the car asks for when it wants the root tabs.
DEFAULT_AUTOSAVE_INTERVAL_MSThe default PersistenceAutosaveOptions.intervalMs: 30 seconds.
DEFAULT_JUMP_SECONDSThe one jump interval, in seconds, applied identically on both platforms.
DEFAULT_PERSISTENCE_KEYDefault storage key. Namespaced so it cannot collide with the app's own.
DEFAULT_PLAYBACK_RESUMPTIONPlayback resumption is off unless the app asks for it.
DEFAULT_REMOTE_VOLUME_CONTROLWhat a remote backend is assumed able to do with its volume.
DEFAULT_REMOTE_VOLUME_STEPSNotches a hardware volume key press moves through when the app says nothing.
DEFAULT_REPEAT_MODEWhat every surface showed before repeatMode existed.
DEFAULT_SHUFFLE_ENABLEDWhat every surface showed before shuffleEnabled existed.
DEFAULT_STOP_FOREGROUND_ON_PAUSEstopForegroundOnPause follows audio_service's default. See PLAN §5.6.
DEFAULT_SUPPORTED_PLAYBACK_RATESMPChangePlaybackRateCommand.supportedPlaybackRates when the app names none.
MAX_COMPACT_CONTROLSAndroid's collapsed media notification has three action slots. media3 will silently drop the overflow; we would rather the app hear about it.
MAX_ROOT_TABSHow many tabs the root may have.
MAX_STOP_FOREGROUND_TIMEOUT_MSmedia3'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).
MediaServiceThe process-wide media session.
MIN_AUTOSAVE_INTERVAL_MSThe floor under PersistenceAutosaveOptions.intervalMs: 1 second.
PERSISTENCE_SCHEMA_VERSIONVersion stamped into every record and required on the way back in.
QueueHandlerwithQueueHandling applied to BaseMediaHandler — the class an app extends when it has no other base.
SESSION_ERROR_SEVERITYThe one place a SessionErrorCode is graded.

Functions

FunctionDescription
applyPersistedBroadcast a restored session, in the order the channels expect.
capRootTabsEnforce the two rules every car's root has, in one place for both platforms.
clearPersistedForget the persisted session.
createMediaServiceBuild a media service over a native hybrid object.
isBrowseErrorStructural BrowseError test — see BrowseError.name.
logSessionErrorWhere a SessionError goes when the app has nowhere for it.
normalizeConfig-
normalizePlaybackStateValidate and fill in a PlaybackState, producing the exact struct the bridge wants. The single choke point: nothing reaches native un-validated.
normalizeRemotePlaybackValidate and fill in a RemotePlayback.
restorePersistedRead back whatever withPersistence last wrote.
stepRemoteVolumeThe volume one hardware key press lands on, as a normalised 0..1 level.
toSessionErrorBuild the SessionError the app sees from what the bridge delivered.
useCarConnectionWhether a car is driving this session, and which kind — re-rendering on every transition.
validateAnchorThe 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-
validateSleepTimerSecondsValidate a sleep-timer duration.
withPersistenceTee the three broadcast channels into storage, so a session survives process death.
withQueueHandlingGive a handler default queue navigation over the data it broadcasts on channel 3.