Monthly Archives: October 2013

Happy Halloween with #MonoMac

As a part of this year’s Halloween celebration, I was asked by my lovely family to whip together something interesting to show on the TV – a whole lot of nothing followed by a scary image and a accompanying scary sound, maintaining the mood during the party.

Our TV is connected to a Mac Mini, acting as our media center, so what better thing than writing some MonoMac code to usher the holiday along!

I started out by creating a new Mac (open source) – MonoMac Project in Xamarin Studio, then configuring the main window to have a black background and to cover the entire screen:

Then, I had my wife gather a bunch of scary images and sounds, which I put in the Resources folder of my solution. Having an idea, graphics and sounds, it was now time to add a BackgroundWorker to the MainWindowController, showing a random image and playing a random sound at a random interval. Lots of randoms!

So, how do we actually show an image and play a sound, you ask? It’s easy as pumpkin pie!

We have 20ish images in the scary app, so I defined a constant (100 (percent)) that indicated that we should hide the currently showing image and stop the currently playing sound. The soundPlayer is an instance of NSSound, supporting all sorts of audio file formats, including .aiff, .wav and .mp3.

The last bit – the actual image display, is simply an Image Well (NSImageView) for which I created an outlet in XCode. I set its contents like so:

That’s it! With Xamarin, coding for the Mac is a breeze! Check out the full source code at Github and adjust it to your needs. Happy Halloween!

 Scroll to top