61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Windows.Controls;
|
|
using JD.Audio.SoundPlayer;
|
|
|
|
namespace JD.Timeline.Karaoke
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for VolumeControl.xaml
|
|
/// </summary>
|
|
public partial class VolumeControl : UserControl
|
|
{
|
|
private IVolume _volume;
|
|
private float _lastVolumeValue;
|
|
|
|
public VolumeControl()
|
|
{
|
|
InitializeComponent();
|
|
Name = "TryGetWave";
|
|
Label.DataContext = this;
|
|
MuteButton.DataContext = this;
|
|
}
|
|
|
|
public IVolume VolumeContext
|
|
{
|
|
get
|
|
{
|
|
return _volume;
|
|
}
|
|
set
|
|
{
|
|
_volume = value;
|
|
if (value != null)
|
|
{
|
|
value.VolumeChanged += OnVolumeChanged;
|
|
}
|
|
VolumeBar.DataContext = value;
|
|
_volume.Volume = PropertyService.PropertyService.Properties.Get("Volume_" + VolumeContext.GetType(), 1.0f);
|
|
}
|
|
}
|
|
|
|
private void OnVolumeChanged(object sender, float volume)
|
|
{
|
|
PropertyService.PropertyService.Properties.Set("Volume_" + VolumeContext.GetType(), volume);
|
|
}
|
|
|
|
public bool IsMuted
|
|
{
|
|
get { return _volume != null && Math.Abs(_volume.Volume) < float.Epsilon; }
|
|
set
|
|
{
|
|
if (_volume != null)
|
|
{
|
|
var temp = _volume.Volume;
|
|
_volume.Volume = !value ? _lastVolumeValue : 0;
|
|
_lastVolumeValue = temp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|