From a1cd0c4871e63d6fa4b8881a7d331213d55798df Mon Sep 17 00:00:00 2001 From: Suvid Singhal Date: Fri, 27 Dec 2024 17:05:48 +0530 Subject: [PATCH 01/14] Added Volume Control Slider to BrainzPlayer --- frontend/css/brainzplayer.less | 1 + .../common/brainzplayer/AppleMusicPlayer.tsx | 13 ++++- .../src/common/brainzplayer/BrainzPlayer.tsx | 1 + .../brainzplayer/BrainzPlayerContext.tsx | 7 +++ .../common/brainzplayer/BrainzPlayerUI.tsx | 26 +++++++++ .../common/brainzplayer/SoundcloudPlayer.tsx | 45 ++++++++------ .../src/common/brainzplayer/SpotifyPlayer.tsx | 14 ++++- .../src/common/brainzplayer/YoutubePlayer.tsx | 58 +++++++++++-------- .../MultiTrackMBIDMappingModal.tsx | 3 +- 9 files changed, 123 insertions(+), 45 deletions(-) diff --git a/frontend/css/brainzplayer.less b/frontend/css/brainzplayer.less index 9f67b334e7..5c5b93cc43 100644 --- a/frontend/css/brainzplayer.less +++ b/frontend/css/brainzplayer.less @@ -300,6 +300,7 @@ opacity: 0.3; } + .dropup-content { // A lot of these styles are copied part from Bootstrap // and part from ListenBrainz (ListenCard). diff --git a/frontend/js/src/common/brainzplayer/AppleMusicPlayer.tsx b/frontend/js/src/common/brainzplayer/AppleMusicPlayer.tsx index ef9ddf8998..7f12637a8e 100644 --- a/frontend/js/src/common/brainzplayer/AppleMusicPlayer.tsx +++ b/frontend/js/src/common/brainzplayer/AppleMusicPlayer.tsx @@ -10,6 +10,7 @@ import { } from "../../utils/utils"; import { DataSourceProps, DataSourceType } from "./BrainzPlayer"; import GlobalAppContext from "../../utils/GlobalAppContext"; +import { BrainzPlayerContext } from "./BrainzPlayerContext"; import { dataSourcesInfo } from "../../settings/brainzplayer/BrainzPlayerSettings"; export type AppleMusicPlayerProps = DataSourceProps; @@ -470,6 +471,16 @@ export default class AppleMusicPlayer if (!show) { return null; } - return
{this.getAlbumArt()}
; + return ( + + {(context) => { + const { volume } = context; + if (this.appleMusicPlayer.player) { + this.appleMusicPlayer.player.volume = volume; + } + return
{this.getAlbumArt()}
; + }} +
+ ); } } diff --git a/frontend/js/src/common/brainzplayer/BrainzPlayer.tsx b/frontend/js/src/common/brainzplayer/BrainzPlayer.tsx index 21ec09ae0e..e8a43dcf55 100644 --- a/frontend/js/src/common/brainzplayer/BrainzPlayer.tsx +++ b/frontend/js/src/common/brainzplayer/BrainzPlayer.tsx @@ -153,6 +153,7 @@ export default function BrainzPlayer() { currentTrackURL, playerPaused, isActivated, + volume, durationMs, progressMs, listenSubmitted, diff --git a/frontend/js/src/common/brainzplayer/BrainzPlayerContext.tsx b/frontend/js/src/common/brainzplayer/BrainzPlayerContext.tsx index 1cac993697..802ab88e2f 100644 --- a/frontend/js/src/common/brainzplayer/BrainzPlayerContext.tsx +++ b/frontend/js/src/common/brainzplayer/BrainzPlayerContext.tsx @@ -40,6 +40,7 @@ export type BrainzPlayerContextT = { currentTrackURL?: string; playerPaused: boolean; isActivated: boolean; + volume: number; durationMs: number; progressMs: number; updateTime: number; @@ -57,6 +58,7 @@ export const initialValue: BrainzPlayerContextT = { currentTrackArtist: "", playerPaused: true, isActivated: false, + volume: 100, durationMs: 0, progressMs: 0, updateTime: performance.now(), @@ -73,6 +75,7 @@ export type BrainzPlayerActionType = Partial & { | "SET_PLAYBACK_TIMER" | "TOGGLE_REPEAT_MODE" | "MOVE_QUEUE_ITEM" + | "VOLUME_CHANGE" | "CLEAR_QUEUE_AFTER_CURRENT_AND_SET_AMBIENT_QUEUE" | "MOVE_AMBIENT_QUEUE_ITEM" | "MOVE_AMBIENT_QUEUE_ITEMS_TO_QUEUE" @@ -179,6 +182,10 @@ function valueReducer( currentListenIndex: newCurrentListenIndex, }; } + case "VOLUME_CHANGE": { + // console.log(action.payload); + return { ...state, volume: action.payload }; + } case "MOVE_AMBIENT_QUEUE_ITEM": { const { ambientQueue } = state; const evt = action.data as any; diff --git a/frontend/js/src/common/brainzplayer/BrainzPlayerUI.tsx b/frontend/js/src/common/brainzplayer/BrainzPlayerUI.tsx index 9bf6579261..a6b90b4543 100644 --- a/frontend/js/src/common/brainzplayer/BrainzPlayerUI.tsx +++ b/frontend/js/src/common/brainzplayer/BrainzPlayerUI.tsx @@ -3,6 +3,7 @@ import { faBarsStaggered, faFastBackward, faFastForward, + faVolumeUp, faHeart, faHeartCrack, faMusic, @@ -75,6 +76,30 @@ function PlaybackControlButton(props: PlaybackControlButtonProps) { ); } +function VolumeControlButton() { + const { volume } = useBrainzPlayerContext(); + const dispatch = useBrainzPlayerDispatch(); + const volumeRef = React.useRef(null); + const handleVolumeChange = () => { + dispatch({ + type: "VOLUME_CHANGE", + payload: volumeRef ? volumeRef.current.value : 100, + }); + }; + return ( + + ); +} + function BrainzPlayerUI(props: React.PropsWithChildren) { const { currentDataSourceName, @@ -262,6 +287,7 @@ function BrainzPlayerUI(props: React.PropsWithChildren) { disabled={disabled} /> +
{isPlayingATrack && currentDataSourceName && ( -