From 2cbc5de3f36879dcd69369c265c1ebac6739e5fe Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 31 Jan 2025 19:10:06 +0100 Subject: [PATCH] Feat: Add (basic) support to select source on player --- src/components/dsp/DSPParametricEQ.vue | 2 +- src/helpers/player_menu_items.ts | 30 +++++++++++++++++++++++++- src/plugins/api/index.ts | 7 ++++++ src/plugins/api/interfaces.ts | 5 ++++- src/translations/en.json | 3 ++- 5 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/components/dsp/DSPParametricEQ.vue b/src/components/dsp/DSPParametricEQ.vue index 13a2f033..e84dda11 100644 --- a/src/components/dsp/DSPParametricEQ.vue +++ b/src/components/dsp/DSPParametricEQ.vue @@ -442,7 +442,7 @@ const preamp = computed({ set: (value) => { peq.value.preamp = value; }, -}) +}); const removeBand = (index: number) => { peq.value.bands.splice(index, 1); diff --git a/src/helpers/player_menu_items.ts b/src/helpers/player_menu_items.ts index cafc4459..814b1847 100644 --- a/src/helpers/player_menu_items.ts +++ b/src/helpers/player_menu_items.ts @@ -30,7 +30,7 @@ export const getPlayerMenuItems = ( }); } // add stop playback menu item - if (player?.state == "playing") { + if (player?.state == "playing" || player?.state == "paused") { menuItems.push({ label: "stop_playback", labelArgs: [], @@ -167,6 +167,34 @@ export const getPlayerMenuItems = ( icon: "mdi-cancel", }); } + + // add 'select source' menu item + const selectableSources = player.source_list.filter((s) => !s.passive); + if ( + player.supported_features.includes(PlayerFeature.SELECT_SOURCE) && + !player.synced_to && + selectableSources.length > 0 + ) { + menuItems.push({ + label: "select_source", + labelArgs: [], + icon: "mdi-import", + subItems: selectableSources + .map((s) => { + return { + label: s.name, + labelArgs: [], + action: () => { + api.playerCommandGroupSelectSource(player.player_id, s.id); + }, + }; + }) + .sort((a, b) => + a.label.toUpperCase() > b.label?.toUpperCase() ? 1 : -1, + ), + }); + } + // add 'don't stop the music' menu item if (playerQueue && "dont_stop_the_music_enabled" in playerQueue) { menuItems.push({ diff --git a/src/plugins/api/index.ts b/src/plugins/api/index.ts index 21eff4fe..eea6c2fd 100644 --- a/src/plugins/api/index.ts +++ b/src/plugins/api/index.ts @@ -1039,6 +1039,13 @@ export class MusicAssistantApi { }); } + public playerCommandGroupSelectSource( + playerId: string, + source: string, + ): Promise { + return this.playerCommand(playerId, "select_source", { source }); + } + // Play Media related functions public playMedia( diff --git a/src/plugins/api/interfaces.ts b/src/plugins/api/interfaces.ts index 642891b7..2863129b 100644 --- a/src/plugins/api/interfaces.ts +++ b/src/plugins/api/interfaces.ts @@ -244,9 +244,12 @@ export enum PlayerFeature { VOLUME_MUTE = "volume_mute", PAUSE = "pause", SET_MEMBERS = "set_members", + MULTI_DEVICE_DSP = "multi_device_dsp", SEEK = "seek", NEXT_PREVIOUS = "next_previous", - ENQUEUE_NEXT = "enqueue_next", + PLAY_ANNOUNCEMENT = "play_announcement", + ENQUEUE = "enqueue", + SELECT_SOURCE = "select_source", } export enum EventType { diff --git a/src/translations/en.json b/src/translations/en.json index 5b84b6ba..d2e8fa98 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -659,5 +659,6 @@ "all_players": "All players", "all_groups": "All groups", "no_player_playing": "No players are currently playing", - "stop_playback": "Stop playback" + "stop_playback": "Stop playback", + "select_source": "Select source" }