Skip to content

Conversation

@ThanhNguyxn
Copy link

Summary of the Pull Request

This PR implements volume persistence for the Peek utility, addressing issue #31810. When users adjust the volume slider for audio or video files in Peek, the volume level is now remembered and applied to subsequent files across sessions.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Implementation Details

The implementation follows the same pattern used for ConfirmFileDelete - a setting that can be modified directly by Peek and synced back to the settings file.

Changes:

  1. Settings Layer (PeekProperties.cs):

    • Added MediaVolume as a DoubleProperty with default value of 1.0 (100%)
  2. User Settings (IUserSettings.cs, UserSettings.cs):

    • Added MediaVolume property with getter/setter
    • Implemented save-to-settings logic that persists volume changes immediately
    • Added value clamping between 0.0 and 1.0
  3. ViewModel (MainWindowViewModel.cs):

    • Added MediaVolume property that delegates to IUserSettings
    • Updated constructor to accept IUserSettings via DI
  4. AudioControl (AudioControl.xaml.cs):

    • Added MediaVolumeProperty DependencyProperty
    • Added VolumeChanged event that fires when user changes volume via transport controls
    • Added volume tracking with _isSettingVolume flag to prevent recursive updates
  5. FilePreview (FilePreview.xaml, FilePreview.xaml.cs):

    • Added MediaVolumeProperty DependencyProperty
    • Added MediaVolumeChanged event
    • Added ApplyMediaVolume() method that sets volume on both video and audio players
    • Subscribes to volume changes from both VideoPreview.MediaPlayer and AudioPreview
  6. MainWindow (MainWindow.xaml, MainWindow.xaml.cs):

    • Added MediaVolume binding to FilePreview
    • Added MediaVolumeChanged event handler that updates ViewModel

How it works

  1. When Peek loads, it reads the saved MediaVolume from settings
  2. The volume flows from MainWindowViewModelFilePreviewAudioControl/VideoPreview
  3. When user adjusts volume via transport controls, the change bubbles up via events
  4. MainWindowViewModel updates IUserSettings.MediaVolume, which saves to settings file
  5. Next time Peek opens or a new file is previewed, the saved volume is applied

Validation Steps Performed

  1. Open Peek with an audio file, adjust volume to 50%
  2. Navigate to another audio file - volume should remain at 50%
  3. Close and reopen Peek - volume should still be at 50%
  4. Open a video file - volume should be at 50%
  5. Adjust video volume to 75%
  6. Open an audio file - volume should be at 75%

Copilot AI review requested due to automatic review settings December 3, 2025 08:43
@ThanhNguyxn
Copy link
Author

@microsoft-github-policy-service agree

Copilot finished reviewing on behalf of ThanhNguyxn December 3, 2025 08:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements volume persistence for the Peek utility, allowing users' volume slider adjustments to be saved and restored across sessions. The implementation follows the established pattern used for other user-modifiable settings like ConfirmFileDelete.

Key Changes

  • Added MediaVolume property (0.0-1.0 range) to settings infrastructure with immediate persistence
  • Implemented bidirectional volume binding from MainWindow through FilePreview to AudioControl and VideoPreview
  • Added volume change event propagation with guards to prevent infinite loops

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/settings-ui/Settings.UI.Library/PeekProperties.cs Added MediaVolume as DoubleProperty with default value of 1.0 (100%)
src/modules/peek/Peek.UI/Services/IUserSettings.cs Added MediaVolume property to interface
src/modules/peek/Peek.UI/Services/UserSettings.cs Implemented MediaVolume getter/setter with clamping and immediate persistence logic
src/modules/peek/Peek.UI/MainWindowViewModel.cs Added MediaVolume property delegating to IUserSettings with proper DI injection
src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml Added binding and event handler for MediaVolume on FilePreview control
src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml.cs Added event handler to update ViewModel when volume changes
src/modules/peek/Peek.FilePreviewer/FilePreview.xaml Added MediaVolume binding to AudioControl
src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs Added volume change event subscriptions, MediaVolumeProperty, and ApplyMediaVolume logic
src/modules/peek/Peek.FilePreviewer/Controls/AudioControl.xaml.cs Added MediaVolumeProperty, volume change event, and ApplyVolume method with guard flag


private void AudioPreview_VolumeChanged(object? sender, double volume)
{
MediaVolumeChanged?.Invoke(this, volume);
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The AudioPreview_VolumeChanged handler should check the _isSettingVolume flag before raising the MediaVolumeChanged event, similar to the MediaPlayer_VolumeChanged handler. Without this guard, programmatically setting the volume on the audio player will trigger a volume change event that bubbles up to the ViewModel and saves to settings, potentially causing an infinite loop or unnecessary settings writes.

private void AudioPreview_VolumeChanged(object? sender, double volume)
{
    if (!_isSettingVolume)
    {
        MediaVolumeChanged?.Invoke(this, volume);
    }
}
Suggested change
MediaVolumeChanged?.Invoke(this, volume);
if (!_isSettingVolume)
{
MediaVolumeChanged?.Invoke(this, volume);
}

Copilot uses AI. Check for mistakes.
@ThanhNguyxn ThanhNguyxn force-pushed the fix/peek-volume-persistence branch 3 times, most recently from e51ccd7 to 673d2ed Compare December 5, 2025 10:52
This commit implements volume persistence for the Peek utility, so that
when users adjust the volume slider for audio/video files, the volume
level is remembered and applied to subsequent files.

Changes:
- Add MediaVolume property to PeekProperties (DoubleProperty, default 1.0)
- Add MediaVolume to IUserSettings interface with getter/setter
- Implement MediaVolume in UserSettings with save-to-settings logic
- Add MediaVolume binding from MainWindow to FilePreview to AudioControl
- Add VolumeChanged events in AudioControl and FilePreview
- Track user volume changes and bubble up to MainWindowViewModel
- Handle volume changes for both audio (AudioControl) and video (MediaPlayerElement)

Fixes microsoft#31810
@ThanhNguyxn ThanhNguyxn force-pushed the fix/peek-volume-persistence branch from 673d2ed to 9393c7e Compare December 5, 2025 11:13
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.

1 participant