Skip to content

Commit

Permalink
feature: configurable dynamic volume slider max and threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
punxaphil committed Mar 11, 2024
1 parent 5225c6e commit 37cba92
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ customSources: # Main use case is probably to set tv media player to play TV sou
- title: TV
thumbnail: https://cdn-icons-png.flaticon.com/512/716/716429.png
dynamicVolumeSlider: true # default is false. See more in section further down.
dynamicVolumeSliderThreshold: 30 # default is 20. Use this to change the threshold for the dynamic volume slider.
dynamicVolumeSliderMax: 40 # default is 30. Use this to change the max value for the dynamic volume slider.
artworkHostname: http://192.168.0.59:8123 #default is ''. Usually not needed, but depending on your setup your device might not be able to access the artwork on the default host. One example where it could be needed is if you cast the dashboard with Google Cast.
showAudioInputFormat: true # default is false. Will show the audio input format (e.g. Dolby Digital) in the player section if available. By default, it will only show if the input format in the volumes section.
fallbackArtwork: https://cdn-icons-png.flaticon.com/512/651/651717.png # Override default fallback artwork image if artwork is missing for the currently selected media.
Expand Down
8 changes: 7 additions & 1 deletion src/components/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Volume extends LitElement {
this.mediaControlService = this.store.mediaControlService;

const volume = this.player.getVolume();
const max = volume < 20 && this.config.dynamicVolumeSlider ? 30 : 100;
const max = this.getMax(volume);

const muteIcon = this.player.isMuted(this.updateMembers) ? mdiVolumeMute : mdiVolumeHigh;
const disabled = this.player.ignoreVolume;
Expand All @@ -44,6 +44,12 @@ class Volume extends LitElement {
`;
}

private getMax(volume: number) {
const dynamicThreshold = Math.max(0, Math.min(this.config.dynamicVolumeSliderThreshold ?? 20, 100));
const dynamicMax = Math.max(0, Math.min(this.config.dynamicVolumeSliderMax ?? 30, 100));
return volume < dynamicThreshold && this.config.dynamicVolumeSlider ? dynamicMax : 100;
}

private async volumeChanged(e: Event) {
const newVolume = numberFromEvent(e);
return await this.mediaControlService.volumeSet(this.player, newVolume, this.updateMembers);
Expand Down
16 changes: 16 additions & 0 deletions src/editor/advanced-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ export const ADVANCED_SCHEMA = [
name: 'dynamicVolumeSlider',
selector: { boolean: {} },
},
{
type: 'integer',
name: 'dynamicVolumeSliderThreshold',
default: 20,
required: true,
valueMin: 1,
valueMax: 100,
},
{
type: 'integer',
name: 'dynamicVolumeSliderMax',
default: 30,
required: true,
valueMin: 1,
valueMax: 100,
},
{
name: 'hideBrowseMediaButton',
selector: { boolean: {} },
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export interface CardConfig extends LovelaceCardConfig {
adjustVolumeRelativeToMainPlayer?: boolean;
skipApplyButtonWhenGrouping?: boolean;
hideVolumeCogwheel?: boolean;
dynamicVolumeSliderThreshold?: number;
dynamicVolumeSliderMax?: number;
}

export interface MediaArtworkOverride {
Expand Down

0 comments on commit 37cba92

Please sign in to comment.