CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Dec 2009
    Posts
    23

    How to avoid delayed audio playback?

    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:
    Code:
    // 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?
    Last edited by TryingToC#; January 9th, 2010 at 06:31 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured