23 May '13 - 09:16 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Playback ended event now working. What's wrong?  (Read 437 times)
kabindi
Posts: 25


« on: 1 Feb '12 - 05:54 »
Reply with quoteQuote

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?

« Last Edit: 1 Feb '12 - 05:57 by kabindi » Logged
Ian @ un4seen
Administrator
Posts: 15269


« Reply #1 on: 1 Feb '12 - 15:27 »
Reply with quoteQuote

That looks like it may be a .Net "garbage collection" issue, ie. your SYNCPROC delegate no longer exists when BASS tries to call it. Please see the SYNCPROC section of the BASS.Net documentation for details and examples.
Logged
kabindi
Posts: 25


« Reply #2 on: 5 Feb '12 - 22:18 »
Reply with quoteQuote

Definitely this was the problem. Thanks for your help!
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines