This project has moved and is read-only. For the latest updates, please go here.

Switching to next song causes NullReferenceException

Oct 16, 2009 at 8:02 PM
Edited Oct 16, 2009 at 8:03 PM

I don't know if this is already in the 'bank' of possible bugs, but i wanted to share this..
Maybe you know something more about it! :)

Like the subject says, when i try to play the next song i use something like this:

btnStop_Click(sender, e);
fileName = "path_to_new_song_file";
btnPlay_Click(sender, e);

One way to get rid of that exception is to sleep the thread for particular amount of milliseconds - in the example, uncommenting the upper line (the 2nd one:)), ..,
but in most ways that isn't quite acceptable.

Exception is raised in the overridden Read method in the MeteringStream.cs file - when program tries to read data from the source stream. 

The better solution, might be something like this:

public override int Read(byte[] buffer, int offset, int count)
    int bytesRead = 0;
        bytesRead = SourceStream.Read(buffer, offset, count);
        ProcessData(buffer, offset, bytesRead);
    return bytesRead;

Some other workaround? Thanks

btnStop_Click(null, null);
            fileName = dgvMusicList.CurrentRow.Cells["MusicColumn_FilePath"].Value.ToString();
            btnPlay_Click(sender, e);
Oct 16, 2009 at 10:01 PM

Hi there,

what callback mechanism are you using with WaveOut? The problem you are experiencing is one I wrote a little about in my recent article on coding4fun: (see the section on callback mechanisms)

also, what version of NAudio are you using?



Oct 17, 2009 at 12:49 AM

Thanks for a quick reply! :)

I used this option: DirectSoundOut....

If i use FunctionCallback, everything freezes on next song.
In the case of NewWindow, it's okay.

WasapiOut works well too without EventSync.

Now i see addition info on: too.

I'm currently on Windows 7.

It's the same with NAudio 1.3, or the SVN version.

Thanks again