Skip to content

Commit

Permalink
MP1-5211: Core: Fix initial volume/mute/table in VolumeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
epbk committed Mar 30, 2024
1 parent 3ba61d5 commit 6bc4cfb
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 137 deletions.
4 changes: 4 additions & 0 deletions mediaportal/Core/Mixer/Mixer10.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ public void Open(int mixerIndex, bool isDigital, int[] volumeTable)
if (_mMdeviceEnumerator == null)
_mMdeviceEnumerator = new MMDeviceEnumerator();

//Init Mute state
if (iAudioEndpointVolume != null)
_isMuted = iAudioEndpointVolume.IsMuted;

var mMdeviceList = _mMdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active);

if (mMdeviceList != null && mMdeviceList.Count > 0)
Expand Down
29 changes: 18 additions & 11 deletions mediaportal/Core/Player/VolumeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,20 @@ public class VolumeHandler

#region Constructors

public VolumeHandler() : this(LoadFromRegistry()) { }
protected VolumeHandler()
{
}

public VolumeHandler(int[] volumeTable)
{
this.Init(volumeTable);
}

#endregion Constructors

#region Methods

protected void Init(int[] volumeTable)
{
if (OSInfo.OSInfo.Win10OrLater())
{
Expand Down Expand Up @@ -98,7 +109,7 @@ public VolumeHandler(int[] volumeTable)
}
catch (Exception ex)
{
Log.Error("VolumeHandler: Mixer exception during init {0}", ex);
Log.Error("VolumeHandler: Init() Mixer exception during init {0}", ex);
}

if (OSInfo.OSInfo.Win8OrLater() && hideWindowsOSD)
Expand Down Expand Up @@ -165,7 +176,7 @@ public VolumeHandler(int[] volumeTable)
}
catch (Exception ex)
{
Log.Error("VolumeHandler: Mixer exception when init {0}", ex);
Log.Error("VolumeHandler: Init() Mixer exception when init {0}", ex);
}

if (OSInfo.OSInfo.Win8OrLater() && hideWindowsOSD)
Expand Down Expand Up @@ -196,11 +207,7 @@ public VolumeHandler(int[] volumeTable)
}

public bool hideWindowsOSD { get; set; }

#endregion Constructors

#region Methods


/// <summary>
/// Create our volume handler singleton.
/// </summary>
Expand Down Expand Up @@ -243,7 +250,7 @@ private static VolumeHandler Create()
{0, 6553, 13106, 19659, 26212, 32765, 39318, 45871, 52424, 58977, 65535});
// windows default from registry
case 1:
return new VolumeHandler();
return new VolumeHandler(LoadFromRegistry());
// logarithmic
case 2:
return new VolumeHandler(new[]
Expand Down Expand Up @@ -296,7 +303,7 @@ private static VolumeHandler Create()
{0, 6553, 13106, 19659, 26212, 32765, 39318, 45871, 52424, 58977, 65535});
// windows default from registry
case 1:
return new VolumeHandler();
return new VolumeHandler(LoadFromRegistry());
// logarithmic
case 2:
return new VolumeHandler(new[]
Expand Down Expand Up @@ -393,7 +400,7 @@ public virtual void UnMute()
}
}

private static int[] LoadFromRegistry()
protected static int[] LoadFromRegistry()
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Multimedia\Audio\VolumeControl"))
{
Expand Down
42 changes: 24 additions & 18 deletions mediaportal/Core/Player/VolumeHandlerCustom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Collections;
using MediaPortal.Configuration;
using MediaPortal.Profile;
using MediaPortal.GUI.Library;

namespace MediaPortal.Player
{
Expand All @@ -36,34 +37,39 @@ public VolumeHandlerCustom()
string text = reader.GetValueAsString("volume", "table",
"0, 4095, 8191, 1638, 12287, 16383, 20479, 24575, 28671, 32767, 36863, 40959, 45055, 49151, 53247, 57343, 61439, 65535");

if (text == string.Empty)
if (!string.IsNullOrWhiteSpace(text))
{
return;
}

ArrayList array = new ArrayList();
ArrayList array = new ArrayList();

try
{
foreach (string volume in text.Split(new char[] {',', ';'}))
try
{
if (volume == string.Empty)
foreach (string volume in text.Split(new char[] {',', ';'}))
{
continue;
if (volume == string.Empty)
{
continue;
}

array.Add(Math.Max(this.Minimum, Math.Min(this.Maximum, int.Parse(volume))));
}

array.Add(Math.Max(this.Minimum, Math.Min(this.Maximum, int.Parse(volume))));
}
array.Sort();

array.Sort();
this.Init((int[])array.ToArray(typeof(int)));

this.Table = (int[])array.ToArray(typeof (int));
}
catch
{
// heh, its undocumented remember, no fancy logging going on here
Log.Debug("VolumeHandlerCustom: ctor() table loaded: {0}", text);

return;
}
catch (Exception ex)
{
Log.Error("VolumeHandlerCustom: ctor() {0}", ex.Message);
}
}
}

//Default
this.Init(LoadFromRegistry());
}

#endregion Constructors
Expand Down
Loading

0 comments on commit 6bc4cfb

Please sign in to comment.