Skip to content

Scale background notification sounds with player volume#1426

Open
SimplyRayYZL wants to merge 2 commits into
CaptainFact:stagingfrom
SimplyRayYZL:fix-background-notification-volume-93
Open

Scale background notification sounds with player volume#1426
SimplyRayYZL wants to merge 2 commits into
CaptainFact:stagingfrom
SimplyRayYZL:fix-background-notification-volume-93

Conversation

@SimplyRayYZL
Copy link
Copy Markdown

Summary

  • Track ReactPlayer volume in VideoPlaybackContext, normalized to the 0..1 range used by HTMLAudioElement.volume.
  • Update the stored volume from ReactPlayer on ready/progress and from DOM volumechange events when available.
  • Apply the current video volume before confirm/refute/neutral background notification sounds play.

Fixes CaptainFact/captain-fact#93

Validation

  • npm run typescript
  • .\node_modules\.bin\eslint.cmd --quiet app\components\App\BackgroundNotifier.jsx app\components\VideoDebate\VideoDebatePlayer.jsx app\contexts\VideoPlaybackContext.jsx
  • .\node_modules\.bin\prettier.cmd --check app\components\App\BackgroundNotifier.jsx app\components\VideoDebate\VideoDebatePlayer.jsx app\contexts\VideoPlaybackContext.jsx
  • git diff --check -- app\contexts\VideoPlaybackContext.jsx app\components\VideoDebate\VideoDebatePlayer.jsx app\components\App\BackgroundNotifier.jsx
  • npm run build

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In playNotificationSound, consider skipping audioFile.play() when the normalized volume is 0 to avoid triggering unnecessary playback operations when the video volume is effectively muted.
  • In getNormalizedPlayerVolume, the internalPlayer.volume branch assumes a 0–1 range; for consistency with the getVolume branch it might be safer to clamp or normalize this value in case some players expose 0–100 there as well.
  • The handleProgress callback now calls updateVolumeFromPlayer on each progress event; if progress events are frequent for some providers, you might want to throttle or compare with the last stored volume before dispatching to reduce redundant context updates.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `playNotificationSound`, consider skipping `audioFile.play()` when the normalized `volume` is 0 to avoid triggering unnecessary playback operations when the video volume is effectively muted.
- In `getNormalizedPlayerVolume`, the `internalPlayer.volume` branch assumes a 0–1 range; for consistency with the `getVolume` branch it might be safer to clamp or normalize this value in case some players expose 0–100 there as well.
- The `handleProgress` callback now calls `updateVolumeFromPlayer` on each progress event; if progress events are frequent for some providers, you might want to throttle or compare with the last stored volume before dispatching to reduce redundant context updates.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Author

Addressed Sourcery's high-level feedback in 89645ee:

  • Skip notification audio playback entirely when the normalized volume is 0.
  • Normalize/clamp both internalPlayer.volume and getVolume() values to the 0..1 range.
  • Avoid redundant volume context dispatches by tracking the last synced player volume before updating from progress/volume events.

Validation re-run:

  • npm run typescript
  • .\node_modules\.bin\eslint.cmd --quiet app\components\App\BackgroundNotifier.jsx app\components\VideoDebate\VideoDebatePlayer.jsx app\contexts\VideoPlaybackContext.jsx
  • .\node_modules\.bin\prettier.cmd --check app\components\App\BackgroundNotifier.jsx app\components\VideoDebate\VideoDebatePlayer.jsx app\contexts\VideoPlaybackContext.jsx
  • git diff --check -- app\components\App\BackgroundNotifier.jsx app\components\VideoDebate\VideoDebatePlayer.jsx
  • npm run build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adapt background sound volume based on video volume

1 participant