I have a little project to do in C#, building an audio player. I tought the best way is to use Microsoft.DirectX.AudioVideoPlayback. I tried to code so that when I push the play button again, the audio file restarts playing(otherwise it plays over the current song). so tha't my play function:

private void play_s_Click(object sender, EventArgs e)
            if (song_path == "none") MessageBox.Show("Please choose an audio file to play.");
                song.CurrentPosition = 0;// I HAVE AN UNHANDLED EXCEPTION HERE !!
                    song = new Audio(song_path, false);
                        playing = true;
                        paused = false;
                        MessageBox.Show("Error. The file could not be loaded.");

The problem is that I have an exception when I try to set the current position of song to 0;
I get this exception: 'NullReferenceException was unhandled'. I also tried to use SeekCurrentPosition. Same result, exception.

Any help will be appreciated. :)

Thanks for your interest Antenka(didn't help, no problem). In fact I would use that when I'll try to move my audio file to a different position. I found other way to RESTART my audio file when pressing the play button again. I simply used a boolean variable. That's not a problem, the problem is when I have to SEEK a position I want in my song(a complete audio player should have this capability).

However, thanks again!

This article has been dead for over six months. Start a new discussion instead.