MonoTouch Port of avTouch

Since the premier of the Apple iPod in 2001 it has been the most popular portable digital music player. Almost 6 years later Apple would release the iPhone which would help users to consolidate several portable gadgets. The iPhone could replace your phone, portable music player, digital camera, portable dvd player, handheld gaming device and reduce the need for its user to wear cargo pants.

One thing that Apple continues to do well is deliver audio entertainment in the form of music, podcasts and audiobooks. As an iOS application developer you are able to use the APIs provided in the SDK to create apps that provide the user audio. This sample will cover some basics of interacting with the AVAudioPlayer in MonoTouch.

The sample I am working with comes from an Apple sample called avTouch. This is not the first MonoTouch port of avPlayer, as Xamaran has already posed a similar example to their iOS samples. However my version does have some improvements over the others.

The biggest difference that the end user would notice is the edit screen that has been added. Using MonoTouch Dialog I have thrown together a quick table view that allows the user to change some behaviors previously only accessible by changing variables buried in the code. These preferences mostly deal with changing the level meter. At runtime you can now change the meter type from openGL to CoreGraphics, number of lights shown on the bar and the intensity of those lights. Also you have the ability to enable and disable variable light intensity and peak level lights.

The next change I made will not be so obvious to the user. In Apple’s version the openGL meter is created using a generic UIView and some typical openGL calls to initialize openGL. In the Xamarin version the GLLevelMeter was not implemented at all. At iOS version 5 the GLKView was introduced to abstract those basic calls to the base class allowing the user to focus on the drawing code. In my version of avTouch I changed the GLLevelMeter class to use the new GLKView.

The final difference with my version is a small bug fix to Apple’s. This fix enables the variable light effect in the openGL version of the meter.

You can access the full sample at one of my GitHub repositories

Future Enhancments

There are some enhancements that I want to implement when I revisit this sample in the near future. First I would like to hook up the RemoteControlReceived call to show how to interact with the app while it is in background mode and playing music. Also work is needed to respect the volume control buttons of iOS devices. Meter enhancements include finding a fix for the problem where the meter abruptly goes to zero when the track ends and creating an openGL meter that uses GLES 2 and the GLKBaseEffect. Finally I am not a big fan of interface builders so one change I would like to make is to layout the player UI programmatically.

Posted in Code | Leave a comment

Lucky Shot

Lucky Shot

Last Monday I want to PNC Park to watch the Pirates play the Mets. I took my Nikon D5000 to the game with the 70-200 2.8 lens attached. I shot well over 500 pics at the game and came home with under 200. I was lucky enough to have the camera ready for the game’s only broken bat.

I did very little post on this pic.  Adjust the sharpness, bumped the contrast and some minimal cropping.

The rest of my shots can be viewed here at my Smug Mug site.

Posted in Photography | Leave a comment