Hi,
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.");
else
{
song.CurrentPosition = 0;// I HAVE AN UNHANDLED EXCEPTION HERE !!
song = new Audio(song_path, false);
try
{
song.Play();
playing = true;
paused = false;
}
catch
{
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. :)