I have implemented a music player and I would love to know when a song is actually ended so I can play the next track. Here is my code:
private void BttnPlayClick(object sender, EventArgs e)
{
string filePath = GetTrackPath();
if (_audioPlayer.PlayPauseFile(filePath))
{
long streamLength = 0;
streamLength = Bass.BASS_ChannelGetLength(_audioPlayer .Stream ) - 1;
Bass.BASS_ChannelSetSync(_audioPlayer.Stream, BASSSync.BASS_SYNC_END,
streamLength, new SYNCPROC(OnTrackEnding), IntPtr.Zero);
}
}
private void OnTrackEnding(int handle, int channel, int data, IntPtr user)
{
MessageBox.Show("Track Ended!");
}
When I run this code, and when the track is ended, I get this NullReferenceException :
System.NullReferenceException was unhandled
Message: Object reference not set to an instance of an object.
Can someone tell what's wrong?