[Solved] SoudPlayer plays the same file again and again [closed]


Inside the Setter for the SoundLocation property is an interesting check:

set
{
    if (value == null)
    {
        value = string.Empty;
    }
    if (!this.soundLocation.Equals(value))
    {
        this.SetupSoundLocation(value);
        this.OnSoundLocationChanged(EventArgs.Empty);
    }
}

You can see that it looks to see if the new location differs from the old one. If it does, then it does some setup work. If it doesn’t, it essentially does nothing.

I’m betting you can get around this by doing something like this:

public static void Play(string fileName)
{
    if (File.Exists(fileName))
    {
        Program.Player.SoundLocation = "";
        Program.Player.SoundLocation = fileName;
        Program.Player.Load();
        if (Program.Player.IsLoadCompleted)
        {
            Program.Player.Play();
        }
    }
}

The first call to the SoundLocation setter would clear out the loaded stream. The second one would then set it up properly with the location again and allow for Load to load the stream as expected.

2

solved SoudPlayer plays the same file again and again [closed]