Skip to content

@camera.ui/sdk / sensor / MediaPlayerControl

Class: MediaPlayerControl<TStorage> ​

Defined in: sensor/mediaPlayer.ts:149

A TV, speaker, receiver or projector. Override setOn(), setOff(), play(), pause(), stop(), next(), previous(), setVolume(), setMuted() and setSource() to drive hardware and call the super method after success. Report what the player does with setState() and what plays with setNowPlaying().

setKind() says what kind of device it is. Narrow the commands to those the player takes with setPropertySpec(MediaPlayerProperty.Command, { values: [...] }). The inputs come as choices with the source capability: setPropertySpec(MediaPlayerProperty.Source, { choices }).

When the device refuses a command, throw from the override instead of calling super: the write fails for whoever sent it and the state stays as it was.

Example ​

ts
class LivingRoomTv extends MediaPlayerControl {
  constructor() {
    super('Living Room TV');
    this.setKind(MediaPlayerKind.Tv);
    this.setPropertySpec(MediaPlayerProperty.Command, { values: [MediaPlayerCommand.Play, MediaPlayerCommand.Pause] });
  }

  override async play(): Promise<void> {
    await tv.play();
    await super.play();
  }
}

Extends ​

Type Parameters ​

TStorage ​

TStorage extends object = Record<string, any>

Constructors ​

Constructor ​

new MediaPlayerControl<TStorage>(name?, options?): MediaPlayerControl<TStorage>

Defined in: sensor/mediaPlayer.ts:152

Parameters ​

name? ​

string = 'Media Player'

options? ​

SensorOptions

Returns ​

MediaPlayerControl<TStorage>

Overrides ​

CommandControl.constructor

Properties ​

category ​

readonly category: Control = SensorCategory.Control

Defined in: sensor/command.ts:25

Category of the sensor: detection sensor, control, trigger or info.

Inherited from ​

CommandControl.category


name ​

readonly name: string

Defined in: sensor/base.ts:406

Name the plugin gave the sensor.

Inherited from ​

CommandControl.name


onAssignmentChanged ​

readonly onAssignmentChanged: Observable<readonly string[]>

Defined in: sensor/base.ts:440

Emits the camera id list whenever the user changes the sensor's camera assignments.

Inherited from ​

Sensor.onAssignmentChanged


onCapabilitiesChanged ​

readonly onCapabilitiesChanged: Observable<MediaPlayerCapability[]>

Defined in: sensor/base.ts:432

Emits the full capability list whenever it changes.

Inherited from ​

CommandControl.onCapabilitiesChanged


onConnectedChanged ​

readonly onConnectedChanged: Observable<boolean>

Defined in: sensor/base.ts:442

Emits when the connected state changes.

Inherited from ​

Sensor.onConnectedChanged


onDeviceInfoChanged ​

readonly onDeviceInfoChanged: Observable<SensorDevice | undefined>

Defined in: sensor/base.ts:446

Emits the device whenever the sensor joins or leaves one, or its device, names or main-sensor role change.

Inherited from ​

Sensor.onDeviceInfoChanged


onPropertyChanged ​

readonly onPropertyChanged: Observable<PropertyChangeOf<MediaPlayerControlProperties>>

Defined in: sensor/base.ts:430

Emits on every property change.

Inherited from ​

CommandControl.onPropertyChanged


onPropertySpecsChanged ​

readonly onPropertySpecsChanged: Observable<Readonly<Record<string, SensorPropertySpec>>>

Defined in: sensor/base.ts:448

Emits the property specs whenever the plugin changes them.

Inherited from ​

Sensor.onPropertySpecsChanged


onSourceStateChanged ​

readonly onSourceStateChanged: Observable<SensorSourceState | undefined>

Defined in: sensor/base.ts:444

Emits when the source state changes.

Inherited from ​

Sensor.onSourceStateChanged


type ​

readonly type: MediaPlayer = SensorType.MediaPlayer

Defined in: sensor/mediaPlayer.ts:150

Type of the sensor, fixed per sensor class.

Overrides ​

CommandControl.type

Accessors ​

address ​

Get Signature ​

get address(): string | undefined

Defined in: sensor/base.ts:487

Current address at the source, e.g. a Home Assistant entity id. Display only.

Returns ​

string | undefined

Inherited from ​

SegmenterSensor.address


artist ​

Get Signature ​

get artist(): string | undefined

Defined in: sensor/mediaPlayer.ts:194

Artist of what plays.

Returns ​

string | undefined


assignedCameraIds ​

Get Signature ​

get assignedCameraIds(): readonly string[]

Defined in: sensor/base.ts:520

Ids of the cameras the user assigned the sensor to.

Returns ​

readonly string[]

Ids of the cameras the user assigned the sensor to.

Inherited from ​

Sensor.assignedCameraIds


assignmentLocked ​

Get Signature ​

get assignmentLocked(): boolean

Defined in: sensor/base.ts:524

Whether the sensor is bound to the camera it was added to, so the user cannot assign it elsewhere.

Returns ​

boolean

Whether the sensor is bound to the camera it was added to, so the user cannot assign it elsewhere.

Inherited from ​

Sensor.assignmentLocked


capabilities ​

Get Signature ​

get capabilities(): TCapability[]

Defined in: sensor/base.ts:545

Capabilities the sensor advertises.

Returns ​

TCapability[]

Set Signature ​

set capabilities(value): void

Defined in: sensor/base.ts:550

Set capabilities, deduplicated, and notify backend plus local listeners.

Parameters ​
value ​

TCapability[]

Returns ​

void

Capabilities the sensor advertises.

Inherited from ​

CommandControl.capabilities


connected ​

Get Signature ​

get connected(): boolean

Defined in: sensor/base.ts:516

Whether the sensor is registered and its plugin is connected.

Returns ​

boolean

Whether the sensor is registered and its plugin is connected.

Inherited from ​

Sensor.connected


deviceInfo ​

Get Signature ​

get deviceInfo(): SensorDevice | undefined

Defined in: sensor/base.ts:499

Device the sensor belongs to, undefined without one and for a camera's own sensor.

Returns ​

SensorDevice | undefined

Device the sensor belongs to, undefined without one and for a camera's own sensor.

Inherited from ​

Sensor.deviceInfo


displayName ​

Get Signature ​

get displayName(): string

Defined in: sensor/base.ts:491

Full name shown to the user: inside a device the device name plus shortName, otherwise the plugin's name until the user renames the sensor.

Returns ​

string

Full name shown to the user: inside a device the device name plus shortName, otherwise the plugin's name until the user renames the sensor.

Inherited from ​

Sensor.displayName


id ​

Get Signature ​

get id(): string

Defined in: sensor/base.ts:468

Entity id of the sensor, provisional on a new sensor until registration.

Returns ​

string

Entity id of the sensor, provisional on a new sensor until registration.

Inherited from ​

Sensor.id


isAssigned ​

Get Signature ​

get isAssigned(): boolean

Defined in: sensor/base.ts:512

Whether the sensor is assigned to at least one camera.

Returns ​

boolean

Inherited from ​

SegmenterSensor.isAssigned


kind ​

Get Signature ​

get kind(): MediaPlayerKind | undefined

Defined in: sensor/mediaPlayer.ts:169

What kind of device it is, a MediaPlayerKind.

Returns ​

MediaPlayerKind | undefined


muted ​

Get Signature ​

get muted(): boolean

Defined in: sensor/mediaPlayer.ts:179

Whether the sound is muted.

Returns ​

boolean


nativeId ​

Get Signature ​

get nativeId(): string | undefined

Defined in: sensor/base.ts:472

Durable identity the plugin supplied, e.g. an upstream device id.

Returns ​

string | undefined

Durable identity the plugin supplied, e.g. an upstream device id.

Inherited from ​

Sensor.nativeId


on ​

Get Signature ​

get on(): boolean

Defined in: sensor/mediaPlayer.ts:159

Whether the player is on, writable with the power capability.

Returns ​

boolean


origin ​

Get Signature ​

get origin(): string | undefined

Defined in: sensor/base.ts:477

Source system the sensor was imported from, e.g. 'homeassistant'.

Returns ​

string | undefined

Inherited from ​

SegmenterSensor.origin


pluginId ​

Get Signature ​

get pluginId(): string | undefined

Defined in: sensor/base.ts:528

Id of the plugin that owns the sensor, set at registration.

Returns ​

string | undefined

Id of the plugin that owns the sensor, set at registration.

Inherited from ​

Sensor.pluginId


primary ​

Get Signature ​

get primary(): boolean

Defined in: sensor/base.ts:503

Whether the sensor is the main sensor of its device, called like the device when it stands alone.

Returns ​

boolean

Whether the sensor is the main sensor of its device, called like the device when it stands alone.

Inherited from ​

Sensor.primary


propertySpecs ​

Get Signature ​

get propertySpecs(): Readonly<Record<string, SensorPropertySpec>>

Defined in: sensor/base.ts:507

Specs of the properties the plugin narrowed or described, resolved against the type's. A property without an entry follows its type's spec.

Returns ​

Readonly<Record<string, SensorPropertySpec>>

Specs of the properties the plugin narrowed or described, resolved against the type's. A property without an entry follows its type's spec.

Inherited from ​

Sensor.propertySpecs


props ​

Get Signature ​

get protected props(): Readonly<TProperties>

Defined in: sensor/base.ts:856

Read-only view of the property values.

Returns ​

Readonly<TProperties>

Inherited from ​

CommandControl.props


shortName ​

Get Signature ​

get shortName(): string

Defined in: sensor/base.ts:495

Name inside its device, the same as displayName for a sensor without a device.

Returns ​

string

Name inside its device, the same as displayName for a sensor without a device.

Inherited from ​

Sensor.shortName


source ​

Get Signature ​

get source(): string | undefined

Defined in: sensor/mediaPlayer.ts:184

Selected input or app, one of the choices the plugin sets.

Returns ​

string | undefined


sourceState ​

Get Signature ​

get sourceState(): SensorSourceState | undefined

Defined in: sensor/base.ts:482

State of the source behind an adopted sensor, as reported with setSourceState().

Returns ​

SensorSourceState | undefined

State of the source behind the sensor. Seen from another plugin it is also unavailable while the camera the sensor belongs to is offline. A sensor that is unavailable or removed takes no writes.

Inherited from ​

Sensor.sourceState


state ​

Get Signature ​

get state(): MediaPlayerState | undefined

Defined in: sensor/mediaPlayer.ts:164

What the player does right now, a MediaPlayerState.

Returns ​

MediaPlayerState | undefined


storage ​

Get Signature ​

get storage(): DeviceStorage<TStorage>

Defined in: sensor/base.ts:533

Per-sensor storage. Throws before registration.

Returns ​

DeviceStorage<TStorage>

Inherited from ​

CommandControl.storage


storageSchema ​

Get Signature ​

get storageSchema(): JsonSchema[]

Defined in: sensor/base.ts:541

JSON schema of the per-sensor settings. Override it to get a settings UI.

Returns ​

JsonSchema[]

Inherited from ​

SegmenterSensor.storageSchema


title ​

Get Signature ​

get title(): string | undefined

Defined in: sensor/mediaPlayer.ts:189

Title of what plays.

Returns ​

string | undefined


volume ​

Get Signature ​

get volume(): number | undefined

Defined in: sensor/mediaPlayer.ts:174

Volume, 0 to 100.

Returns ​

number | undefined

Methods ​

getValue() ​

Call Signature ​

getValue<K>(property): MediaPlayerControlProperties[K] | undefined

Defined in: sensor/base.ts:574

Get the current value of a sensor property. Calling the generic overload with a property enum value gives a properly typed result.

Type Parameters ​
K ​

K extends keyof MediaPlayerControlProperties

Parameters ​
property ​

K

Returns ​

MediaPlayerControlProperties[K] | undefined

Inherited from ​

CommandControl.getValue

Call Signature ​

getValue(property): unknown

Defined in: sensor/base.ts:575

Get the current value of a sensor property. Calling the generic overload with a property enum value gives a properly typed result.

Parameters ​
property ​

string

Returns ​

unknown

Inherited from ​

CommandControl.getValue


getValues() ​

getValues(): Readonly<TProperties>

Defined in: sensor/base.ts:591

Get a read-only snapshot of all property values.

Returns ​

Readonly<TProperties>

Shallow copy of every property currently held by the sensor.

Example ​

ts
const snapshot = sensor.getValues();
console.log(snapshot);

Inherited from ​

CommandControl.getValues


hasCapability() ​

hasCapability(capability): boolean

Defined in: sensor/base.ts:634

Check whether the sensor advertises a capability.

Parameters ​

capability ​

string

Capability flag to look for.

Returns ​

boolean

True if the sensor currently advertises it.

Example ​

ts
const dimmable = sensor.hasCapability('brightness');

Inherited from ​

CommandControl.hasCapability


next() ​

next(): Promise<void>

Defined in: sensor/mediaPlayer.ts:272

Skip to the next track or channel. Override to drive hardware and call await super.next() after success.

Returns ​

Promise<void>

Example ​

ts
await player.next();

onStart() ​

protected onStart(): void | Promise<void>

Defined in: sensor/base.ts:953

Lifecycle hook, called once the sensor is registered and live (storage and RPC are wired up). Override it to start work whose lifetime matches the sensor's: polling loops, event subscriptions, timers.

Errors thrown here are swallowed, not logged. Handle failures inside the override. Paired 1:1 with onStop, which runs on removal, plugin shutdown or cleanup.

Returns ​

void | Promise<void>

Example ​

ts
protected override onStart(): void {
  this._timer = setInterval(() => this.poll(), 5_000);
}

Inherited from ​

CommandControl.onStart


onStop() ​

protected onStop(): void | Promise<void>

Defined in: sensor/base.ts:966

Counterpart of onStart: tear down whatever it started, such as timers, subscriptions and external resources.

Returns ​

void | Promise<void>

Example ​

ts
protected override onStop(): void {
  if (this._timer) clearInterval(this._timer);
}

Inherited from ​

CommandControl.onStop


pause() ​

pause(): Promise<void>

Defined in: sensor/mediaPlayer.ts:246

Pause playback. Override to drive hardware and call await super.pause() after success.

Returns ​

Promise<void>

Example ​

ts
await player.pause();

play() ​

play(): Promise<void>

Defined in: sensor/mediaPlayer.ts:233

Start or resume playback. Override to drive hardware and call await super.play() after success.

Returns ​

Promise<void>

Example ​

ts
await player.play();

previous() ​

previous(): Promise<void>

Defined in: sensor/mediaPlayer.ts:285

Go back to the previous track or channel. Override to drive hardware and call await super.previous() after success.

Returns ​

Promise<void>

Example ​

ts
await player.previous();

setAddress() ​

setAddress(address): void

Defined in: sensor/base.ts:669

Report the sensor's current address at the source, e.g. after a Home Assistant entity was renamed. The identity (nativeId) stays.

Parameters ​

address ​

string

Current address at the source

Returns ​

void

Example ​

typescript
sensor.setAddress(entry.entity_id);

Inherited from ​

CommandControl.setAddress


setDeviceInfo() ​

setDeviceInfo(device, options?): void

Defined in: sensor/base.ts:692

Put the sensor into a device, or take it out with undefined. Sensors of this plugin that report the same DeviceInfo.id form one device. Pass the device in the constructor options when it is known there, call this for what changes later: a new firmware, a rename at the source. Only a change reaches the host. Ignored for a sensor added with camera.addSensor(), its camera is its device.

Parameters ​

device ​

DeviceInfo | undefined

Device at the source, undefined to take the sensor out of its device

options? ​

SetDeviceInfoOptions

Whether this sensor is the device's main sensor

Returns ​

void

Example ​

typescript
sensor.setDeviceInfo({ id: hub.serial, name: hub.name, manufacturer: 'Acme', firmware: hub.version }, { primary: true });

Inherited from ​

CommandControl.setDeviceInfo


setDisplayName() ​

setDisplayName(value): void

Defined in: sensor/base.ts:566

Set the display name (the only mutable identifier on a sensor).

Parameters ​

value ​

string

Human-readable label shown in the UI.

Returns ​

void

Example ​

ts
sensor.setDisplayName('Front Door Motion');

Inherited from ​

CommandControl.setDisplayName


setKind() ​

setKind(kind): void

Defined in: sensor/mediaPlayer.ts:361

Say what kind of device the player is. Smart homes show it by its kind, and Home Assistant takes it as the device class.

Parameters ​

kind ​

MediaPlayerKind

TV, speaker, receiver or projector.

Returns ​

void

Example ​

ts
player.setKind(MediaPlayerKind.Speaker);

setMuted() ​

setMuted(muted): Promise<void>

Defined in: sensor/mediaPlayer.ts:316

Mute or unmute the sound. Override to drive hardware and call await super.setMuted(muted) after success.

Parameters ​

muted ​

boolean

Whether the sound is muted.

Returns ​

Promise<void>

Example ​

ts
await player.setMuted(true);

setNowPlaying() ​

setNowPlaying(title?, artist?): void

Defined in: sensor/mediaPlayer.ts:379

Report what plays, needs the nowPlaying capability. Leave both out when nothing plays.

Parameters ​

title? ​

string

Title of the track, show or channel.

artist? ​

string

Artist of the track.

Returns ​

void

Example ​

ts
player.setNowPlaying('So What', 'Miles Davis');

setOff() ​

setOff(): Promise<void>

Defined in: sensor/mediaPlayer.ts:220

Turn the player off. Override to drive hardware and call await super.setOff() after success.

Returns ​

Promise<void>

Example ​

ts
await player.setOff();

setOn() ​

setOn(): Promise<void>

Defined in: sensor/mediaPlayer.ts:207

Turn the player on. Override to drive hardware and call await super.setOn() after success.

Returns ​

Promise<void>

Example ​

ts
await player.setOn();

setPropertySpec() ​

setPropertySpec<K>(property, spec): void

Defined in: sensor/base.ts:717

Narrow or describe one property for this device: a range and step, the enum values it supports, the choices it offers with their names, a text limit. The host rejects a command outside it before it reaches the plugin. Pass it in the constructor options when it is known there, call this for what changes later. Only a change reaches the host.

Type Parameters ​

K ​

K extends MediaPlayerProperty

Parameters ​

property ​

K

Property to describe

spec ​

PropertySpecOverride | undefined

What the device accepts, undefined to follow the type's spec again

Returns ​

void

Example ​

typescript
alarm.setPropertySpec(SecuritySystemProperty.TargetState, {
  values: [SecuritySystemState.AwayArm, SecuritySystemState.StayArm, SecuritySystemState.Disarmed],
});

Inherited from ​

CommandControl.setPropertySpec


setSource() ​

setSource(value): Promise<void>

Defined in: sensor/mediaPlayer.ts:331

Switch to another input or app. Override to drive hardware and call await super.setSource(value) after success.

Parameters ​

value ​

string

One of the source choices.

Returns ​

Promise<void>

Example ​

ts
await player.setSource('hdmi1');

setSourceState() ​

setSourceState(state): void

Defined in: sensor/base.ts:651

Report what the source behind this sensor looks like right now, for example unavailable while the device can't be reached. The host shows the state with its reason on the sensors page and never deletes on it. While it is unavailable or removed the sensor takes no writes.

Parameters ​

state ​

SensorSourceState

Current source state

Returns ​

void

Example ​

typescript
sensor.setSourceState(registryHasEntity ? 'connected' : 'removed');

Inherited from ​

CommandControl.setSourceState


setState() ​

setState(value): void

Defined in: sensor/mediaPlayer.ts:346

Report what the player does right now. on follows: everything but off counts as on.

Parameters ​

value ​

MediaPlayerState

Off, on, idle, playing, paused or buffering.

Returns ​

void

Example ​

ts
player.setState(MediaPlayerState.Playing);

setVolume() ​

setVolume(volume): Promise<void>

Defined in: sensor/mediaPlayer.ts:300

Set the volume. Override to drive hardware and call await super.setVolume(volume) after success to sync the SDK state.

Parameters ​

volume ​

number

0 to 100, clamped and rounded.

Returns ​

Promise<void>

Example ​

ts
await player.setVolume(30);

stop() ​

stop(): Promise<void>

Defined in: sensor/mediaPlayer.ts:259

Stop playback. Override to drive hardware and call await super.stop() after success.

Returns ​

Promise<void>

Example ​

ts
await player.stop();

updateModelSpec() ​

updateModelSpec(): void

Defined in: sensor/base.ts:875

Re-announces the model spec, e.g. once the models finished loading.

The spec a detector reports at registration is what it knows at that moment: models that load in the background are missing from it. Call this after loading, the server replaces its copy.

Returns ​

void

Example ​

typescript
async onStart(): Promise<void> {
  await this.loadModel();
  this.updateModelSpec();
}

Inherited from ​

CommandControl.updateModelSpec


updateValue() ​

updateValue(property, value): Promise<void>

Defined in: sensor/base.ts:617

Generic property write coming from a consumer. Control sensors dispatch it to their semantic methods (setOn, setActive, setTargetState), so plugin overrides drive the hardware. Writes run one at a time per sensor in arrival order, a newer value of a property replaces one still waiting, a command always runs. Unknown or non-writable properties are ignored.

Plugin authors call the semantic methods on the concrete class instead.

Parameters ​

property ​

string

Property to write.

value ​

unknown

Value to write.

Returns ​

Promise<void>

Resolves once the device took the value, rejects with the setter's error, when nothing answered within 10 seconds or while the source is unavailable or removed.

Example ​

ts
await light.updateValue(LightProperty.Brightness, 80);

Inherited from ​

CommandControl.updateValue