Switching to next song causes NullReferenceException

Oct 16, 2009 at 7:02 PM
Edited Oct 16, 2009 at 7: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 9: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:

http://blogs.msdn.com/coding4fun/archive/2009/10/08/9905168.aspx (see the section on callback mechanisms)

also, what version of NAudio are you using?



Oct 16, 2009 at 11:49 PM

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: http://mark-dot-net.blogspot.com/2008/11/waveoutopen-callbacks-in-naudio.html too.

I'm currently on Windows 7.

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

Thanks again