Skip to content

Commit abc781d

Browse files
committed
Fix the Volume control does not work #1578
1 parent 41fa5ed commit abc781d

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs

+3-23
Original file line numberDiff line numberDiff line change
@@ -339,39 +339,19 @@ private void UpdateMeta(string path, MediaInfoLib info)
339339
}
340340
}
341341

342-
// Newer .net has Math.Clamp
343-
private T Clamp<T>(T val, T min, T max) where T : IComparable<T>
344-
{
345-
if (val.CompareTo(min) < 0) return min;
346-
else if (val.CompareTo(max) > 0) return max;
347-
else return val;
348-
}
349-
350-
// A change in amplitude by a factor of 10 corresponds to a 20 dB change
351-
private const double DecibelAmplitudeMult = 20.0;
352-
353342
public double LinearVolume
354343
{
355-
// mediaElement.Volume returns [0,1] where 0 = -100db, 1 = 0db
356-
// Decibel is logarithmic. See amplitude table https://en.wikipedia.org/wiki/Decibel
357-
get
358-
{
359-
var dbVol = 100.0 * (mediaElement.Volume - 1.0);
360-
var linearVol = Math.Pow(10, dbVol / DecibelAmplitudeMult);
361-
return linearVol;
362-
}
344+
get => mediaElement.Volume;
363345
set
364346
{
365-
var linearVol = Clamp(value, 0.00001, 1.0);
366-
var dbVol = DecibelAmplitudeMult * Math.Log10(linearVol);
367-
mediaElement.Volume = dbVol / 100.0 + 1.0;
347+
mediaElement.Volume = value;
368348
OnPropertyChanged();
369349
}
370350
}
371351

372352
private void ChangeVolume(double delta)
373353
{
374-
LinearVolume = LinearVolume + delta; // setter will clamp
354+
LinearVolume += delta;
375355
}
376356

377357
private void TogglePlayPause(object sender, EventArgs e)

0 commit comments

Comments
 (0)