I am learning event handling in C #, creating an application using the iTunes COM API. I have a method that should start when iTunes stops playing the song, but the method is never called when I fire the event in the application by clicking the Stop / Pause button.
EDIT . Based on dboarman's answer, I removed the while loop. Now the event is being processed, but only if I restart iTunes before running PlayPlaylist (). If the second time I launched PlayPlaylist (), the stop event will no longer be fired / processed.
void trayIcon_Click(object sender, EventArgs e)
{
PlayPlaylist();
}
public static void PlayPlaylist()
{
itapp = new iTunesApp();
itapp.OnPlayerStopEvent +=
new _IiTunesEvents_OnPlayerStopEventEventHandler(itapp_OnPlayerStopEvent);
lastPlaylist = itapp.LibraryPlaylist;
itapp.Play();
}
static void itapp_OnPlayerStopEvent(object iTrack)
{
Debug.WriteLine("Stop Event fired");
}
Updated source at Pastebin here (lines 59-68 are relevant).
Spec: Genius (iTunes Genius ). StopEvent .