Overview
Package mediaplayer is Home Assistant's media_player domain: its types.
Entity controls one media_player entity over HTTP.
No method for media_player.browse_media and media_player.search_media, which only answer with data: call api.Client.CallServiceForResponse.
Home Assistant documents the domain here:
Integration: https://www.home-assistant.io/integrations/media_player/
Entity model (developers): https://contributors.home-assistant.io/core/entities/media-player/
Control
// client is an *api.Client
target := mediaplayer.Get(client, "my_media_player")
state, err := target.State(ctx)
err = target.ClearPlaylist(ctx)
Commands
What each Entity method does on each transport. Home Assistant has no MQTT discovery for this domain.
| Method | Over HTTP, calls |
|---|---|
ClearPlaylist |
media_player.clear_playlist |
Join |
media_player.join |
MediaNextTrack |
media_player.media_next_track |
MediaPause |
media_player.media_pause |
MediaPlay |
media_player.media_play |
MediaPlayPause |
media_player.media_play_pause |
MediaPreviousTrack |
media_player.media_previous_track |
MediaSeek |
media_player.media_seek |
MediaStop |
media_player.media_stop |
PlayMedia |
media_player.play_media |
RepeatSet |
media_player.repeat_set |
SelectSoundMode |
media_player.select_sound_mode |
SelectSource |
media_player.select_source |
ShuffleSet |
media_player.shuffle_set |
Toggle |
media_player.toggle |
TurnOff |
media_player.turn_off |
TurnOn |
media_player.turn_on |
Unjoin |
media_player.unjoin |
VolumeDown |
media_player.volume_down |
VolumeMute |
media_player.volume_mute |
VolumeSet |
media_player.volume_set |
VolumeUp |
media_player.volume_up |
Services without a method
Call these with the REST or WebSocket client.
| Service | Why |
|---|---|
media_player.browse_media | it only answers with data |
media_player.search_media | it only answers with data |
Control
type Entity struct
Entity controls one media_player entity over HTTP (api.Client). State and Subscribe come from the embedded Handle.
Embeds entity.Handle[Attributes], whose methods it has too.
func Get(transport entity.Transport, id string) *Entity
Get returns the media_player entity with the given id: an entity id over HTTP (the "media_player." prefix may be omitted). It does no I/O.
func List(ctx context.Context, transport entity.Transport) ([]*Entity, error)
List returns every media_player entity the transport can see.
func (e *Entity) ClearPlaylist(ctx context.Context) error
ClearPlaylist calls media_player.clear_playlist. It has no MQTT equivalent. Core describes the service: Removes all items from a media player's playlist.
func (e *Entity) Join(ctx context.Context, options ...entity.ServiceOption) error
Join calls media_player.join. It has no MQTT equivalent. Core describes the service: Groups media players together for synchronous playback. Only works on supported multiroom audio systems.
func (e *Entity) MediaNextTrack(ctx context.Context) error
MediaNextTrack calls media_player.media_next_track. It has no MQTT equivalent. Core describes the service: Selects the next track on a media player.
func (e *Entity) MediaPause(ctx context.Context) error
MediaPause calls media_player.media_pause. It has no MQTT equivalent. Core describes the service: Pauses playback on a media player.
func (e *Entity) MediaPlay(ctx context.Context) error
MediaPlay calls media_player.media_play. It has no MQTT equivalent. Core describes the service: Starts playback on a media player.
func (e *Entity) MediaPlayPause(ctx context.Context) error
MediaPlayPause calls media_player.media_play_pause. It has no MQTT equivalent. Core describes the service: Toggles play/pause on a media player.
func (e *Entity) MediaPreviousTrack(ctx context.Context) error
MediaPreviousTrack calls media_player.media_previous_track. It has no MQTT equivalent. Core describes the service: Selects the previous track on a media player.
func (e *Entity) MediaSeek(ctx context.Context, options ...entity.ServiceOption) error
MediaSeek calls media_player.media_seek. It has no MQTT equivalent. Core describes the service: Allows you to go to a different part of the media that is currently playing on a media player.
func (e *Entity) MediaStop(ctx context.Context) error
MediaStop calls media_player.media_stop. It has no MQTT equivalent. Core describes the service: Stops playback on a media player.
func (e *Entity) PlayMedia(ctx context.Context, options ...entity.ServiceOption) error
PlayMedia calls media_player.play_media. It has no MQTT equivalent. Core describes the service: Starts playing specified media on a media player.
func (e *Entity) RepeatSet(ctx context.Context, options ...entity.ServiceOption) error
RepeatSet calls media_player.repeat_set. It has no MQTT equivalent. Core describes the service: Sets the repeat mode of a media player.
func (e *Entity) SelectSoundMode(ctx context.Context, options ...entity.ServiceOption) error
SelectSoundMode calls media_player.select_sound_mode. It has no MQTT equivalent. Core describes the service: Selects a specific sound mode of a media player.
func (e *Entity) SelectSource(ctx context.Context, options ...entity.ServiceOption) error
SelectSource calls media_player.select_source. It has no MQTT equivalent. Core describes the service: Sends a media player the command to change the input source.
func (e *Entity) ShuffleSet(ctx context.Context, options ...entity.ServiceOption) error
ShuffleSet calls media_player.shuffle_set. It has no MQTT equivalent. Core describes the service: Enables or disables the shuffle mode of a media player.
func (e *Entity) Toggle(ctx context.Context) error
Toggle calls media_player.toggle. It has no MQTT equivalent. Core describes the service: Toggles a media player on/off.
func (e *Entity) TurnOff(ctx context.Context) error
TurnOff calls media_player.turn_off. It has no MQTT equivalent. Core describes the service: Turns off the power of a media player.
func (e *Entity) TurnOn(ctx context.Context) error
TurnOn calls media_player.turn_on. It has no MQTT equivalent. Core describes the service: Turns on the power of a media player.
func (e *Entity) Unjoin(ctx context.Context) error
Unjoin calls media_player.unjoin. It has no MQTT equivalent. Core describes the service: Removes a media player from a group. Only works on platforms which support player groups.
func (e *Entity) VolumeDown(ctx context.Context) error
VolumeDown calls media_player.volume_down. It has no MQTT equivalent. Core describes the service: Turns down the volume of a media player.
func (e *Entity) VolumeMute(ctx context.Context, options ...entity.ServiceOption) error
VolumeMute calls media_player.volume_mute. It has no MQTT equivalent. Core describes the service: Mutes or unmutes a media player.
func (e *Entity) VolumeSet(ctx context.Context, options ...entity.ServiceOption) error
VolumeSet calls media_player.volume_set. It has no MQTT equivalent. Core describes the service: Sets the volume level of a media player.
func (e *Entity) VolumeUp(ctx context.Context) error
VolumeUp calls media_player.volume_up. It has no MQTT equivalent. Core describes the service: Turns up the volume of a media player.
type State = entity.State[Attributes]
State is a snapshot of one media_player entity.
func Announce(value bool) entity.ServiceOption
Announce sets the "announce" service data field.
func Enqueue(value string) entity.ServiceOption
Enqueue sets the "enqueue" service data field.
func GroupMembers(value []string) entity.ServiceOption
GroupMembers sets the "group_members" service data field.
func IsVolumeMuted(value bool) entity.ServiceOption
IsVolumeMuted sets the "is_volume_muted" service data field.
func Media(value map[string]any) entity.ServiceOption
Media sets the "media" service data field.
func Repeat(value string) entity.ServiceOption
Repeat sets the "repeat" service data field.
func SeekPosition(value float64) entity.ServiceOption
SeekPosition sets the "seek_position" service data field.
func Shuffle(value bool) entity.ServiceOption
Shuffle sets the "shuffle" service data field.
func SoundMode(value string) entity.ServiceOption
SoundMode sets the "sound_mode" service data field.
func Source(value string) entity.ServiceOption
Source sets the "source" service data field.
func VolumeLevel(value float64) entity.ServiceOption
VolumeLevel sets the "volume_level" service data field.
State and values
type Attributes struct
Attributes are the state attributes of a media_player entity, under the names Home Assistant publishes them with.
See: https://www.home-assistant.io/integrations/media_player/
| Field | Type | Wire key | Description |
|---|---|---|---|
AppId | *string | app_id | App ID. |
AppName | *string | app_name | App. |
DeviceClass | *DeviceClass | device_class | |
MediaImageLocal | *string | entity_picture_local | Local accessible entity picture. |
GroupMembers | *[]string | group_members | |
IsVolumeMuted | *bool | is_volume_muted | Muted. |
MediaAlbumArtist | *string | media_album_artist | Album artist. |
MediaAlbumName | *string | media_album_name | Album. |
MediaArtist | *string | media_artist | Artist. |
MediaChannel | *string | media_channel | Channel. |
MediaContentId | *string | media_content_id | Content ID. |
MediaContentType | *string | media_content_type | Content type. |
MediaDuration | *int | media_duration | Duration. |
MediaEpisode | *string | media_episode | Episode. |
MediaPlaylist | *string | media_playlist | Playlist. |
MediaPosition | *int | media_position | Position. |
MediaPositionUpdatedAt | *ha.DateTime | media_position_updated_at | Position updated. |
MediaSeason | *string | media_season | Season. |
MediaSeriesTitle | *string | media_series_title | Series. |
MediaTitle | *string | media_title | Title. |
MediaTrack | *int | media_track | Track. |
Repeat | *string | repeat | Repeat. |
Shuffle | *bool | shuffle | Shuffle. |
SoundMode | *string | sound_mode | Sound mode. |
SoundModeList | *[]string | sound_mode_list | Available sound modes. |
Source | *string | source | Source. |
SourceList | *[]string | source_list | Available sources. |
SupportedFeatures | Feature | supported_features | A set of Feature flags. |
VolumeLevel | *float64 | volume_level | Volume. |
DeviceClass
type DeviceClass string
DeviceClass is core's MediaPlayerDeviceClass.
| Constant | Value |
|---|---|
DeviceClassUnknown | "Unknown" |
DeviceClassTv | "tv" |
DeviceClassSpeaker | "speaker" |
DeviceClassReceiver | "receiver" |
DeviceClassProjector | "projector" |
func DeviceClassFromString(s string) DeviceClass
DeviceClassFromString returns the DeviceClass spelled s, by its value or by the name of core's member, and DeviceClassUnknown for anything else.
func (v *DeviceClass) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling DeviceClassFromString accepts.
Feature
type Feature uint64
Feature is a set of media_player supported features, with the values of core's MediaPlayerEntityFeature: the supported_features attribute decodes into it.
| Constant | Value |
|---|---|
FeatureUnknown | 0 |
FeaturePause | 1 << 0 |
FeatureSeek | 1 << 1 |
FeatureVolumeSet | 1 << 2 |
FeatureVolumeMute | 1 << 3 |
FeaturePreviousTrack | 1 << 4 |
FeatureNextTrack | 1 << 5 |
FeatureTurnOn | 1 << 7 |
FeatureTurnOff | 1 << 8 |
FeaturePlayMedia | 1 << 9 |
FeatureVolumeStep | 1 << 10 |
FeatureSelectSource | 1 << 11 |
FeatureStop | 1 << 12 |
FeatureClearPlaylist | 1 << 13 |
FeaturePlay | 1 << 14 |
FeatureShuffleSet | 1 << 15 |
FeatureSelectSoundMode | 1 << 16 |
FeatureBrowseMedia | 1 << 17 |
FeatureRepeatSet | 1 << 18 |
FeatureGrouping | 1 << 19 |
FeatureMediaAnnounce | 1 << 20 |
FeatureMediaEnqueue | 1 << 21 |
FeatureSearchMedia | 1 << 22 |
func FeatureFromString(s string) Feature
FeatureFromString returns the Feature spelled s, by its value or by the name of core's member, and FeatureUnknown for anything else.
MediaClass
type MediaClass string
MediaClass is core's MediaClass.
| Constant | Value |
|---|---|
MediaClassUnknown | "Unknown" |
MediaClassAlbum | "album" |
MediaClassApp | "app" |
MediaClassArtist | "artist" |
MediaClassChannel | "channel" |
MediaClassComposer | "composer" |
MediaClassContributingArtist | "contributing_artist" |
MediaClassDirectory | "directory" |
MediaClassEpisode | "episode" |
MediaClassGame | "game" |
MediaClassGenre | "genre" |
MediaClassImage | "image" |
MediaClassMovie | "movie" |
MediaClassMusic | "music" |
MediaClassPlaylist | "playlist" |
MediaClassPodcast | "podcast" |
MediaClassSeason | "season" |
MediaClassTrack | "track" |
MediaClassTvShow | "tv_show" |
MediaClassUrl | "url" |
MediaClassVideo | "video" |
func MediaClassFromString(s string) MediaClass
MediaClassFromString returns the MediaClass spelled s, by its value or by the name of core's member, and MediaClassUnknown for anything else.
func (v *MediaClass) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling MediaClassFromString accepts.
MediaContentType
type MediaContentType string
MediaContentType lists the built-in values of the media_content_type attribute, as Home Assistant translates them. Integrations may use others, which are kept as they are.
| Constant | Value |
|---|---|
MediaContentTypeUnknown | "Unknown" |
MediaContentTypeAlbum | "album" |
MediaContentTypeApp | "app" |
MediaContentTypeArtist | "artist" |
MediaContentTypeChannel | "channel" |
MediaContentTypeChannels | "channels" |
MediaContentTypeComposer | "composer" |
MediaContentTypeContributingArtist | "contributing_artist" |
MediaContentTypeEpisode | "episode" |
MediaContentTypeGame | "game" |
MediaContentTypeGenre | "genre" |
MediaContentTypeImage | "image" |
MediaContentTypeMovie | "movie" |
MediaContentTypeMusic | "music" |
MediaContentTypePlaylist | "playlist" |
MediaContentTypePodcast | "podcast" |
MediaContentTypeSeason | "season" |
MediaContentTypeTrack | "track" |
MediaContentTypeTvshow | "tvshow" |
MediaContentTypeUrl | "url" |
MediaContentTypeVideo | "video" |
func MediaContentTypeFromString(s string) MediaContentType
MediaContentTypeFromString returns s as a MediaContentType.
func (v *MediaContentType) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling MediaContentTypeFromString accepts.
MediaPlayerEnqueue
type MediaPlayerEnqueue string
MediaPlayerEnqueue is core's MediaPlayerEnqueue.
| Constant | Value |
|---|---|
MediaPlayerEnqueueUnknown | "Unknown" |
MediaPlayerEnqueueAdd | "add" |
MediaPlayerEnqueueNext | "next" |
MediaPlayerEnqueuePlay | "play" |
MediaPlayerEnqueueReplace | "replace" |
func MediaPlayerEnqueueFromString(s string) MediaPlayerEnqueue
MediaPlayerEnqueueFromString returns the MediaPlayerEnqueue spelled s, by its value or by the name of core's member, and MediaPlayerEnqueueUnknown for anything else.
func (v *MediaPlayerEnqueue) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling MediaPlayerEnqueueFromString accepts.
MediaType
type MediaType string
MediaType is core's MediaType.
| Constant | Value |
|---|---|
MediaTypeUnknown | "Unknown" |
MediaTypeAlbum | "album" |
MediaTypeApp | "app" |
MediaTypeApps | "apps" |
MediaTypeArtist | "artist" |
MediaTypeChannel | "channel" |
MediaTypeChannels | "channels" |
MediaTypeComposer | "composer" |
MediaTypeContributingArtist | "contributing_artist" |
MediaTypeEpisode | "episode" |
MediaTypeGame | "game" |
MediaTypeGenre | "genre" |
MediaTypeImage | "image" |
MediaTypeMovie | "movie" |
MediaTypeMusic | "music" |
MediaTypePlaylist | "playlist" |
MediaTypePodcast | "podcast" |
MediaTypeSeason | "season" |
MediaTypeTrack | "track" |
MediaTypeTvshow | "tvshow" |
MediaTypeUrl | "url" |
MediaTypeVideo | "video" |
func MediaTypeFromString(s string) MediaType
MediaTypeFromString returns the MediaType spelled s, by its value or by the name of core's member, and MediaTypeUnknown for anything else.
func (v *MediaType) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling MediaTypeFromString accepts.
RepeatMode
type RepeatMode string
RepeatMode is core's RepeatMode.
| Constant | Value |
|---|---|
RepeatModeUnknown | "Unknown" |
RepeatModeAll | "all" |
RepeatModeOff | "off" |
RepeatModeOne | "one" |
func RepeatModeFromString(s string) RepeatMode
RepeatModeFromString returns the RepeatMode spelled s, by its value or by the name of core's member, and RepeatModeUnknown for anything else.
func (v *RepeatMode) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling RepeatModeFromString accepts.
RepeatValue
type RepeatValue string
RepeatValue lists the built-in values of the repeat attribute, as Home Assistant translates them. Integrations may use others, which are kept as they are.
| Constant | Value |
|---|---|
RepeatValueUnknown | "Unknown" |
RepeatValueAll | "all" |
RepeatValueOff | "off" |
RepeatValueOne | "one" |
func RepeatValueFromString(s string) RepeatValue
RepeatValueFromString returns s as a RepeatValue.
func (v *RepeatValue) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling RepeatValueFromString accepts.
StateValue
type StateValue string
StateValue is core's MediaPlayerState.
| Constant | Value |
|---|---|
StateValueUnknown | "Unknown" |
StateValueOff | "off" |
StateValueOn | "on" |
StateValueIdle | "idle" |
StateValuePlaying | "playing" |
StateValuePaused | "paused" |
StateValueStandby | "standby" |
StateValueBuffering | "buffering" |
func StateValueFromString(s string) StateValue
StateValueFromString returns the StateValue spelled s, by its value or by the name of core's member, and StateValueUnknown for anything else.
func (v *StateValue) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling StateValueFromString accepts.