C# Tutorial – Play Multiple sound files in Windows Form Application

In this tutorial we will demonstrate how to play multiple audio files in Windows Forms with C# programming. Audio is very important to games development, a must have good music and sound effects and they should be blended into the game so the player doesn’t notice them but knows they are there. In the past tutorials we used the Sound Player class to play simple sound effects in games but we haven’t covered a tutorial where you can play the background sound and a sound effect in a game yet. The sound player is very useful but its not practical for games development as the main audio player. For example you cannot play two sound files simultaneously during run time. The sound player class will stop the other sound from playing before loading and playing a new sound file.  This is where we can use the Media Player windows form component to ensure have steady music playing in the background and we can mix it up with the sound player class to play any sound effects we want to play in it.

Lesson Objectives –

  1. Import the media player component to windows forms toolbox
  2. Use the media player component to Load MP3 files during the run time
  3. Use sound player and media player together
  4. Use buttons to control the play and stop functionalities of the media player
  5. Learn how to repeat sound files or music in the media player with C#

Video

Download the sound files for this project

Full Source Code –

 

 




Comment on this tutorial and let us know how you got on -