Click to See Complete Forum and Search --> : How to avoid delayed audio playback?


TryingToC#
January 9th, 2010, 05:27 AM
Hello everyone!

I successfully build a little programme that does everything I wanted it to do. One of the crucial functions of that app is playing sounds when certain buttons are pressed.

I tried different approaches and settled on this one:

// make sure to add a reference to COM --> Windows Media Player (wmp.dll)
WMPLib.WindowsMediaPlayer Player;

private void PlayFile(String Location)
{
// Taken from http://msdn.microsoft.com/en-us/library/dd562692(VS.85).aspx
Player = new WMPLib.WindowsMediaPlayer();
Player.URL = Location;
Player.controls.play();
}

private void button1_Click(object sender, EventArgs e)
{
// A hypothetical button that'd trigger the sound
String FileLocation = "C:\\thefoldercontainingthesoundfile(s)\\samplesound.mp3";

if (System.IO.File.Exists(FileLocation))
PlayFile(FileLocation);
else
MessageBox.Show("The file could not be found.", "Error");
}


When I fire up the programme and press the play-sound-button for the first time, there is a delay of about one second. After that, playback is smooth and instant. However, on my girlfriend's computer (which is weaker) there always is a delay of about one second.

Is there a way to avoid such a delay on weaker machines?