public override void Start() {
// If we are supposed to play an application resource, try to load it
if (!String.IsNullOrEmpty(this.ResourceName)) {
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string assemblyName = executingAssembly.GetName().Name;
Stream stream = executingAssembly.GetManifestResourceStream(assemblyName + "." + this.ResourceName);
if (stream != null)
this.Player = new SoundPlayer(stream);
}
if (!String.IsNullOrEmpty(this.FileName)) {
this.Player = new SoundPlayer(this.FileName);
}
// We could just use Play() and let the player handle the threading for us, but:
// - there is no builtin way to know when the sound has finished
// - on XP (at least), using Play() on a Stream gives noise -- but PlaySync() works fine.
this.done = false;
Thread newThread = new Thread((ThreadStart)delegate {
if (this.SystemSound != null)
this.SystemSound.Play();
else {
if (this.Player != null)
this.Player.PlaySync();
}
this.done = true;
});
newThread.Start();
}
bool done;