Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multi-select, pick random sound #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions UI/Components/SoundComponent.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,33 @@ private void PlaySound(string location, int volume)
{
Player.Stop();

if (Activated && File.Exists(location))
if (location != null && location.Length != 0)
{
Task.Factory.StartNew(() =>
String[] sounds = location.Split(new[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
var rnd = new Random();
int sIndex = rnd.Next(sounds.Length);

var soundLocation = sounds[sIndex];

if (Activated && File.Exists(soundLocation))
{
try
Task.Factory.StartNew(() =>
{
AudioFileReader audioFileReader = new AudioFileReader(location);
audioFileReader.Volume = (volume / 100f) * (Settings.GeneralVolume / 100f);
try
{
AudioFileReader audioFileReader = new AudioFileReader(soundLocation);
audioFileReader.Volume = (volume / 100f) * (Settings.GeneralVolume / 100f);

Player.DeviceNumber = Settings.OutputDevice;
Player.Init(audioFileReader);
Player.Play();
}
catch (Exception e)
{
Log.Error(e);
}
});
Player.DeviceNumber = Settings.OutputDevice;
Player.Init(audioFileReader);
Player.Play();
}
catch (Exception e)
{
Log.Error(e);
}
});
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions UI/Components/SoundSettings.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,18 @@ protected string BrowseForPath(TextBox textBox, Action<string> callback)
var fileDialog = new OpenFileDialog()
{
FileName = path,
Filter = "Audio Files|*.mp3;*.wav;*.aiff;*.wma|All Files|*.*"
Filter = "Audio Files|*.mp3;*.wav;*.aiff;*.wma|All Files|*.*",
Multiselect = true
};

var result = fileDialog.ShowDialog();

if (result == DialogResult.OK)
path = fileDialog.FileName;
path = "";
foreach (String file in fileDialog.FileNames)
{
path = path + "," + file;
}

textBox.Text = path;
callback(path);
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we can't return an array of strings here instead?

Copy link
Author

@FrozenSake FrozenSake Jul 10, 2021

Choose a reason for hiding this comment

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

No, that should work, and would be smoother. I'm currently laid up from Vaxx # 2, but I can look into cleaning that up this weekend hopefully.

Copy link
Author

@FrozenSake FrozenSake Jul 11, 2021

Choose a reason for hiding this comment

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

I'm looking in to it now. It "works", but problems comes up with SettingsHelper. I'm currently fiddling to figure out how to get it to behave correctly, specifically around loading settings and saving empty fields.

{{EDIT: It may actually be the text box data binding that's the issue}}

Copy link
Author

Choose a reason for hiding this comment

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

It was both. I think I handled it now.

Expand Down