Gapless (looping) audio playback with DirectX in C#

Posted by horsedrowner on Stack Overflow See other posts from Stack Overflow or by horsedrowner
Published on 2010-03-17T16:21:00Z Indexed on 2010/03/17 16:51 UTC
Read the original article Hit count: 244

Filed under:
|
|

I'm currently using the following code (C#):

    private static void PlayLoop(string filename)
    {
        Audio player = new Audio(filename);
        player.Play();
        while (player.Playing)
        {
            if (player.CurrentPosition >= player.Duration)
            {
                player.SeekCurrentPosition(0, SeekPositionFlags.AbsolutePositioning);
            }
            System.Threading.Thread.Sleep(100);
        }
    }

This code works, and the file I'm playing is looping. But, obviously, there is a small gap between each playback.

  • I tried reducing the Thread.Sleep it to 10 or 5, but the gap remains.
  • I also tried removing it completely, but then the CPU usage raises to 100% and there's still a small gap.

Is there any (simple) way to make playback in DirectX gapless? It's not a big deal since it's only a personal project, but if I'm doing something foolish or otherwise completely wrong, I'd love to know.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about c#

Related posts about directx