Search code examples
c#wavaudio-playersoundplayer

Play sound from WAV file at a time offset from start in C#


I'm trying to coordinate playing sound with displaying some other data on a graph recorded at the same time. If the user drags the graph forward or backwards how can I skip forward or backward in the WAV file so the sound is still coordinated? I can't see a time offset in APIs like SoundPlayer.


Solution

  • if i understood your question correctly, then use WMPLib.WindowsMediaPlayer , add reference to "Windows Media Player" from COM and then you set the position by using:

     WMPLib.WindowsMediaPlayer player = new  WMPLib.WindowsMediaPlayer();
     player.URL = file; //file to be played
     player.controls.play();
     player.controls.currentPosition = x; //set the position you want here when user drag
    

    or you can use naudio, free opensource API, download it from codeplex:

    Naudio Library