1

Hi i'm building my first RPG game in windows form. I'm currently trying to set a default background music that runs on boot and doesn't stop. If i set the axWindowsMediaPlayer to visible and press play it runs without any problems with that simple line :

    private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
    {
        axWindowsMediaPlayer1.URL = @"MyMusic\\ff3.mp3";
    }

Its the click event but I can find any "On boot event". I've read somewhere that the default axWindowsMediaPlayer.settings.autorun was true but just to make sure I added that line into my load event :

    private void Form1_Load(object sender, EventArgs e)
    axWindowsMediaPlayer1.settings.autoStart = true;

But still no sound on boot any ideas?

Yahel
  • 37,023
  • 22
  • 103
  • 153
phadaphunk
  • 12,785
  • 15
  • 73
  • 107

1 Answers1

2

Why don't you use SoundPlayer Class? If you are building a game it's better this than your solution. So you can load your sound file writing this code:

using System.Media;

public SoundPlayer LoadSoundFile(string filename)
{
       SoundPlayer sound = null;

       try
       {
             sound = new SoundPlayer();
             sound.SoundLocation = filename;
             sound.Load();
       }
       catch (Exception ex)
       {
             MessageBox.Show(ex.Message, "Error loading sound");
       }

       return sound;         
}

Then you can Play() and Stop() your sound when you want.

EDIT:

In your case:

private void Form1_Load(object sender, EventArgs e)
{
     LoadSoundFile(filename).Play();  
}

PS: Remember that you have to convert your .mp3 files to .wav

user973511
  • 329
  • 3
  • 11