Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 14 additions & 1 deletion UI/Components/SoundComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class SoundComponent : LogicComponent, IDeactivatableComponent
private SoundSettings Settings { get; set; }
private WaveOut Player { get; set; }

private Random rnd;

public SoundComponent(LiveSplitState state)
{
Activated = true;
Expand All @@ -35,6 +37,8 @@ public SoundComponent(LiveSplitState state)
State.OnPause += State_OnPause;
State.OnResume += State_OnResume;
State.OnReset += State_OnReset;

rnd = new Random();
}

public override void Dispose()
Expand Down Expand Up @@ -160,10 +164,19 @@ private void State_OnReset(object sender, TimerPhase e)
PlaySound(Settings.Reset, Settings.ResetVolume);
}

private void PlaySound(string location, int volume)
private void PlaySound(string locations, int volume)
{
Player.Stop();

int index = 0;
string[] locationsArray = locations.Split(';');
if (locationsArray.Length > 1)
{
index = rnd.Next(0, locations.Length);
}

string location = locationsArray[index];

Comment on lines +171 to +179
Copy link
Author

Choose a reason for hiding this comment

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

This is kinda questionable, should make some kind of regex-parser for paths so they could contain semicolon symbol

if (Activated && File.Exists(location))
{
Task.Factory.StartNew(() =>
Expand Down
5 changes: 3 additions & 2 deletions UI/Components/SoundSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,15 @@ protected string BrowseForPath(TextBox textBox, Action<string> callback)
var path = textBox.Text;
var fileDialog = new OpenFileDialog()
{
FileName = path,
Multiselect = true,
FileName = path.Split(';')[0],
Filter = "Audio Files|*.mp3;*.wav;*.aiff;*.wma|All Files|*.*"
};

var result = fileDialog.ShowDialog();

if (result == DialogResult.OK)
path = fileDialog.FileName;
path = String.Join(";", fileDialog.FileNames);

textBox.Text = path;
callback(path);
Expand Down