Skip to content

Implement Theme Song Volume Control #6674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ config.json

# environment related
.envrc

# other
repomix.config.json
repomix-output.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Checkbox from '@mui/material/Checkbox';
import Slider from '@mui/material/Slider';
import FormControl from '@mui/material/FormControl';
import FormControlLabel from '@mui/material/FormControlLabel';
import FormHelperText from '@mui/material/FormHelperText';
Expand All @@ -13,10 +14,11 @@ import type { DisplaySettingsValues } from '../types/displaySettingsValues';

interface LibraryPreferencesProps {
onChange: (event: React.SyntheticEvent) => void;
onSliderChange: () => (event: Event, value: number | number[]) => void;
values: DisplaySettingsValues;
}

export function LibraryPreferences({ onChange, values }: Readonly<LibraryPreferencesProps>) {
export function LibraryPreferences({ onChange, onSliderChange, values }: Readonly<LibraryPreferencesProps>) {
return (
<Stack spacing={3}>
<Typography variant='h2'>{globalize.translate('HeaderLibraries')}</Typography>
Expand Down Expand Up @@ -79,6 +81,30 @@ export function LibraryPreferences({ onChange, values }: Readonly<LibraryPrefere
</FormHelperText>
</FormControl>

<FormControl fullWidth>
<FormControlLabel
aria-describedby='display-settings-lib-theme-song-volume-level-description'
control={
<Slider
disabled={!values.enableLibraryThemeSongs}
valueLabelDisplay='auto'
value={values.libraryThemeSongsVolumeLevel}
marks
defaultValue={50}
min={0}
max={100}
step={5}
onChange={onSliderChange}
/>
}
label={globalize.translate('LabelThemeSongVolume')}
name='libraryThemeSongsVolumeLevel'
/>
<FormHelperText id='display-settings-lib-theme-song-volume-level-description'>
{globalize.translate('ThemeSongVolumeHelp')}
</FormHelperText>
</FormControl>

<FormControl fullWidth>
<FormControlLabel
aria-describedby='display-settings-lib-theme-videos-description'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ async function loadDisplaySettings({
enableItemDetailsBanner: Boolean(settings.detailsBanner()),
enableLibraryBackdrops: Boolean(settings.enableBackdrops()),
enableLibraryThemeSongs: Boolean(settings.enableThemeSongs()),
libraryThemeSongsVolumeLevel: settings.themeSongsVolumeLevel(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was supposed to be in alphabetical order.

enableLibraryThemeVideos: Boolean(settings.enableThemeVideos()),
enableRewatchingInNextUp: Boolean(settings.enableRewatchingInNextUp()),
episodeImagesInNextUp: Boolean(settings.useEpisodeImagesInNextUpAndResume()),
Expand Down Expand Up @@ -132,6 +133,7 @@ async function saveDisplaySettings({
userSettings.detailsBanner(newDisplaySettings.enableItemDetailsBanner);
userSettings.enableBackdrops(newDisplaySettings.enableLibraryBackdrops);
userSettings.enableThemeSongs(newDisplaySettings.enableLibraryThemeSongs);
userSettings.themeSongsVolumeLevel(newDisplaySettings.libraryThemeSongsVolumeLevel);
userSettings.enableThemeVideos(newDisplaySettings.enableLibraryThemeVideos);
userSettings.enableRewatchingInNextUp(newDisplaySettings.enableRewatchingInNextUp);
userSettings.useEpisodeImagesInNextUpAndResume(newDisplaySettings.episodeImagesInNextUp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface DisplaySettingsValues {
enableItemDetailsBanner: boolean;
enableLibraryBackdrops: boolean;
enableLibraryThemeSongs: boolean;
libraryThemeSongsVolumeLevel: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was supposed to be in alphabetical order.

enableLibraryThemeVideos: boolean;
enableRewatchingInNextUp: boolean;
episodeImagesInNextUp: boolean;
Expand Down
14 changes: 14 additions & 0 deletions src/apps/experimental/routes/user/display/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ export default function UserDisplayPreferences() {
}
}, [updateField, values]);

const handleSliderChange = useCallback(() => (e: Event, newValue: number | number[]) => {
const target = e.target as HTMLInputElement;
const fieldName = target.name as keyof DisplaySettingsValues;
const value = Array.isArray(newValue) ? newValue[0] : newValue;

if (values?.[fieldName] !== value) {
updateField({
name: fieldName,
value: value.toString()
});
}
}, [updateField, values]);

Comment on lines +43 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't handleFieldChange (onChange callback) enough?

if (loading || !values) {
return <LoadingComponent />;
}
Expand All @@ -66,6 +79,7 @@ export default function UserDisplayPreferences() {
/>
<LibraryPreferences
onChange={handleFieldChange}
onSliderChange={handleSliderChange}
values={values}
/>
<NextUpPreferences
Expand Down
20 changes: 20 additions & 0 deletions src/components/displaySettings/displaySettings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import escapeHtml from 'escape-html';
import dom from '../../scripts/dom';
import browser from '../../scripts/browser';
import layoutManager from '../layoutManager';
import { pluginManager } from '../pluginManager';
Expand Down Expand Up @@ -67,6 +68,19 @@ function showOrHideMissingEpisodesField(context) {
context.querySelector('.fldDisplayMissingEpisodes').classList.remove('hide');
}

function updateThemeSongVolumeDisabledState(context) {
const isEnabled = context.querySelector('#chkThemeSong').checked;
const sliderElement = context.querySelector('#sliderThemeSongVolume');
sliderElement.disabled = !isEnabled;

sliderElement.classList.toggle('disabled', !isEnabled);
// Find the slider container and toggle the disabled class on it
const sliderContainer = dom.parentWithClass(sliderElement, 'sliderContainer-settings');
if (sliderContainer) {
sliderContainer.classList.toggle('disabled', !isEnabled);
}
}

function loadForm(context, user, userSettings) {
if (appHost.supports('displaylanguage')) {
context.querySelector('.languageSection').classList.remove('hide');
Expand Down Expand Up @@ -115,6 +129,11 @@ function loadForm(context, user, userSettings) {
context.querySelector('.chkDisplayMissingEpisodes').checked = user.Configuration.DisplayMissingEpisodes || false;

context.querySelector('#chkThemeSong').checked = userSettings.enableThemeSongs();
context.querySelector('#chkThemeSong').addEventListener('change', function() {
updateThemeSongVolumeDisabledState(context);
});
context.querySelector('#sliderThemeSongVolume').value = userSettings.themeSongsVolumeLevel();
updateThemeSongVolumeDisabledState(context);
context.querySelector('#chkThemeVideo').checked = userSettings.enableThemeVideos();
context.querySelector('#chkFadein').checked = userSettings.enableFastFadein();
context.querySelector('#chkBlurhash').checked = userSettings.enableBlurhash();
Expand Down Expand Up @@ -150,6 +169,7 @@ function saveUser(context, user, userSettingsInstance, apiClient) {
userSettingsInstance.dateTimeLocale(context.querySelector('.selectDateTimeLocale').value);

userSettingsInstance.enableThemeSongs(context.querySelector('#chkThemeSong').checked);
userSettingsInstance.themeSongsVolumeLevel(context.querySelector('#sliderThemeSongVolume').value);
userSettingsInstance.enableThemeVideos(context.querySelector('#chkThemeVideo').checked);
userSettingsInstance.theme(context.querySelector('#selectTheme').value);
userSettingsInstance.dashboardTheme(context.querySelector('#selectDashboardTheme').value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ <h2 class="sectionTitle">
<div class="fieldDescription checkboxFieldDescription">${EnableThemeSongsHelp}</div>
</div>

<div class="sliderContainer-settings">
<div class="sliderContainer">
<input is="emby-slider" id="sliderThemeSongVolume" label="${LabelThemeSongVolume}" type="range" min="0" max="100" step="1" value="50" />
</div>
<div class="fieldDescription">${ThemeSongVolumeHelp}</div>
</div>

<div class="checkboxContainer checkboxContainer-withDescription fldThemeVideo">
<label>
<input type="checkbox" is="emby-checkbox" id="chkThemeVideo" />
Expand Down
8 changes: 8 additions & 0 deletions src/elements/emby-slider/emby-slider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@
height: 2.83em; /* similar to emby-input with its 110% font-size */
}

.sliderContainer-settings.disabled {
opacity: 0.5;
}

.sliderContainer-settings.disabled .sliderBubble {
display: none;
}

.sliderLabel {
display: block;
margin-bottom: 0.25em;
Expand Down
14 changes: 14 additions & 0 deletions src/scripts/settings/userSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ export class UserSettings {
return toBoolean(this.get('enableThemeSongs', false), false);
}

/**
* Get or set 'Theme Songs' volume level.
* @param {number|undefined} [val] - Volume level to set.
* @return {number} Current volume level.
*/
themeSongsVolumeLevel(val) {
if (val !== undefined) {
return this.set('themeSongsVolumeLevel', val.toString());
}

return parseInt(this.get('themeSongsVolumeLevel') || '100', 10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it would be better to make the default volume lower.

Suggested change
return parseInt(this.get('themeSongsVolumeLevel') || '100', 10);
return parseInt(this.get('themeSongsVolumeLevel') || '50', 10);

}

/**
* Get or set 'Theme Videos' state.
* @param {boolean|undefined} [val] - Flag to enable 'Theme Videos' or undefined.
Expand Down Expand Up @@ -676,6 +689,7 @@ export const selectAudioNormalization = currentSettings.selectAudioNormalization
export const enableNextVideoInfoOverlay = currentSettings.enableNextVideoInfoOverlay.bind(currentSettings);
export const enableVideoRemainingTime = currentSettings.enableVideoRemainingTime.bind(currentSettings);
export const enableThemeSongs = currentSettings.enableThemeSongs.bind(currentSettings);
export const themeSongsVolumeLevel = currentSettings.themeSongsVolumeLevel.bind(currentSettings);
export const enableThemeVideos = currentSettings.enableThemeVideos.bind(currentSettings);
export const enableFastFadein = currentSettings.enableFastFadein.bind(currentSettings);
export const enableBlurhash = currentSettings.enableBlurhash.bind(currentSettings);
Expand Down
2 changes: 2 additions & 0 deletions src/strings/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@
"LabelTextWeight": "Text weight",
"Bold": "Bold",
"LabelTheme": "Theme",
"LabelThemeSongVolume": "Theme song volume",
"LabelTime": "Time",
"LabelTimeLimitHours": "Time limit (hours)",
"LabelTitle": "Title",
Expand Down Expand Up @@ -1578,6 +1579,7 @@
"TellUsAboutYourself": "Tell us about yourself",
"TextSent": "Text sent.",
"ThemeSongs": "Theme songs",
"ThemeSongVolumeHelp": "Adjust the volume of theme songs played while browsing the library.",
"ThemeVideos": "Theme videos",
"TheseSettingsAffectSubtitlesOnThisDevice": "These settings affect subtitles on this device",
"ThisWizardWillGuideYou": "This wizard will help guide you through the setup process. To begin, please select your preferred language.",
Expand Down
Loading