I was playing with a music module this morning and noticed that if a MusicFinished event handler was not defined a null exception occurred in the module driver.
I suspect that the driver does not check the MusicFinished event for null before calling it.
if (MusicFinished != null)
MusicFinished(...);
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
namespace GadgeteerMusicModuleTest
{
public partial class Program
{
private byte[] song = null;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
button.ButtonReleased += new Button.ButtonEventHandler(button_ButtonReleased);
song = Resources.GetBytes(Resources.BinaryResources.PhoneRingInternal);
// null exception if the following line is commented out
music.MusicFinished += new MusicFinishedPlayingEventHandler(music_MusicFinished);
}
void music_MusicFinished()
{
Debug.Print("Music finished");
}
void button_ButtonReleased(Button sender, Button.ButtonState state)
{
music.Play(song);
}
}
}