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. :)

Recommended Answers

Don't know, how fix it, but I found something to turn off function, that calls the exception (and a little info about that) ...
http://msdn.microsoft.com/en-us/library/d21c150d.aspx

Jump to Post

All 2 Replies

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.