added ability to swap between audio devices

This commit is contained in:
iAmAsval 2020-05-15 01:16:58 +02:00
parent 771e48a594
commit f1b6601054
7 changed files with 73 additions and 9 deletions

View File

@ -83,6 +83,18 @@ namespace FModel.Properties {
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string AudioPlayerDevice {
get {
return ((string)(this["AudioPlayerDevice"]));
}
set {
this["AudioPlayerDevice"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]

View File

@ -17,6 +17,9 @@
<Setting Name="AutoOpenSounds" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="AudioPlayerDevice" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="StaticAesKeys" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>

View File

@ -52,7 +52,7 @@ namespace FModel.Utils
{
// i can use TestAesKey here but that means it's gonna test here then right after to set the key
// so a try catch when setting the key seems better
menuItem.PakFile.AesKey = sKey.ToBytesKey();
menuItem.PakFile.AesKey = sKey.Trim().ToBytesKey();
}
catch (System.Exception e)
{
@ -72,7 +72,7 @@ namespace FModel.Utils
{
// i can use TestAesKey here but that means it's gonna test here then right after to set the key
// so a try catch when setting the key seems better
menuItem.PakFile.AesKey = dKey.ToBytesKey();
menuItem.PakFile.AesKey = dKey.Trim().ToBytesKey();
}
catch (System.Exception e)
{

View File

@ -1,4 +1,5 @@
using FModel.Windows.SoundPlayer.Visualization;
using System.Collections.ObjectModel;
using System.Windows;
namespace FModel.ViewModels.SoundPlayer
@ -32,18 +33,18 @@ namespace FModel.ViewModels.SoundPlayer
public class InputFileViewModel : PropertyChangedBase
{
private Device _device = Device.GetDefaultDevice();
private ObservableCollection<Device> _devices = new ObservableCollection<Device>(Device.GetOutputDevices());
private bool _isEnabled = true;
private string _content;
private string _bytes;
private string _duration;
private float _volume = 0.5f;
public Device Device
public ObservableCollection<Device> Devices
{
get { return _device; }
get { return _devices; }
set { this.SetProperty(ref this._device, value); }
set { this.SetProperty(ref this._devices, value); }
}
public bool IsEnabled
{

View File

@ -81,8 +81,8 @@
<Button Grid.Column="1" Grid.Row="7" Content="{x:Static properties:Resources.Open}"
Click="OnOpenClick" Height="19" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
<TextBox Grid.Column="3" Grid.Row="1" TextWrapping="NoWrap"
Style="{StaticResource ResourceKey=SelectableTextBox}" Text="{Binding Device.Name, Mode=TwoWay}"/>
<ComboBox x:Name="AudioDevices_CmbBox" Grid.Column="3" Grid.Row="1"
DisplayMemberPath="Name" SelectionChanged="OnSelectionChanged"/>
<TextBox Grid.Column="3" Grid.Row="2" TextWrapping="NoWrap"
Style="{StaticResource ResourceKey=SelectableTextBox}" Text="{Binding Content, Mode=TwoWay}"/>
<TextBox Grid.Column="3" Grid.Row="3" TextWrapping="NoWrap"

View File

@ -4,7 +4,9 @@ using FModel.Windows.SoundPlayer.Visualization;
using Microsoft.Win32;
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace FModel.Windows.SoundPlayer
@ -36,7 +38,10 @@ namespace FModel.Windows.SoundPlayer
{
DiscordIntegration.SaveCurrentPresence();
AudioPlayer_TabItm.DataContext = InputFileVm.inputFileViewModel;
output = new OutputSource(InputFileVm.inputFileViewModel.Device);
AudioDevices_CmbBox.ItemsSource = InputFileVm.inputFileViewModel.Devices;
AudioDevices_CmbBox.SelectedItem = InputFileVm.inputFileViewModel.Devices.Where(x => x.DeviceId == Properties.Settings.Default.AudioPlayerDevice).FirstOrDefault();
if (AudioDevices_CmbBox.SelectedIndex < 0) AudioDevices_CmbBox.SelectedIndex = 0;
if (spectrumAnalyzer == null)
spectrumAnalyzer = new UserControls.SpectrumAnalyzer(output);
if (timeline == null)
@ -107,5 +112,19 @@ namespace FModel.Windows.SoundPlayer
PlayPauseImg.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/play.png"));
}
}
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is ComboBox c && c.SelectedItem is Device d)
{
Properties.Settings.Default.AudioPlayerDevice = d.DeviceId;
Properties.Settings.Default.Save();
if (output == null)
output = new OutputSource(d);
else
output.SwapDevice(d);
}
}
}
}

View File

@ -482,6 +482,35 @@ namespace FModel.Windows.SoundPlayer.Visualization
return false;
}
public bool SwapDevice(Device d)
{
if (_soundOut != null)
{
bool wasPlaying = IsPlaying;
bool wasPaused = Paused;
TimeSpan pos = Position;
outputDevice = d;
if (wasPlaying || wasPaused)
{
_soundOut.Stop();
}
LoadSoundOut();
_waveSource.SetPosition(pos);
if (wasPlaying)
_soundOut.Play();
else if (wasPaused)
{
_soundOut.Play();
_soundOut.Pause();
}
}
return true;
}
#endregion
#region Events