Skip to content

Commit

Permalink
Feat: Add (basic) support to select source on player
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Jan 31, 2025
1 parent 89382e6 commit 2cbc5de
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/dsp/DSPParametricEQ.vue
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ const preamp = computed({
set: (value) => {
peq.value.preamp = value;
},
})
});
const removeBand = (index: number) => {
peq.value.bands.splice(index, 1);
Expand Down
30 changes: 29 additions & 1 deletion src/helpers/player_menu_items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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({
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,13 @@ export class MusicAssistantApi {
});
}

public playerCommandGroupSelectSource(
playerId: string,
source: string,
): Promise<void> {
return this.playerCommand(playerId, "select_source", { source });
}

// Play Media related functions

public playMedia(
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/api/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 2cbc5de

Please sign in to comment.