Freigeben über


Windows Phone App 4: BabySoother

They say necessity is the mother of invention... A new baby plus a few weeks of paternity leave were the drivers in this case. The idea for this app started as a simple white-noise generator, and was basically a big “Play” button that played a recording of me saying “Shhhh”. Soon after I realized that my new boy reacted better to his mother’s voice than to most other things – so I wondered how to get that incorporated.

So this app now does the following:

  • Plays one of several background sounds in a loop, for a predetermined time period
  • Occasionally overlays that with clips that you record yourself (e.g.; my wife’s voice)

image

During the advanced testing phase (i.e.; trying to get the baby to sleep), I would switch this on, and put it somewhere near him. Works like a charm (for different values of “charm”, depending on his level of anxiety ;))!!

Trial version is available; won’t play for very long. Check it out:

BabySoother

 

From a development point of view, I had some difficulties with this seemingly simple application:

  • It’s quite “thready”, there are inter-thread interactions for things such as stopping the sounds after a given time (and/or when the user clicks “stop”), dealing with the microphone input, overlaying sounds, etc. Lots of callbacks being thrown around, lots of places to watch out for cross-thread access.
  • It was my first experience with XNA (in this case, for sound recording), and I had to play around with things before getting the microphone recording working well.
    • Some of that was due to a bug in the interaction between the Zune software and the Emulator (I think), meaning that sounds wouldn’t play, and I thought I had a bug – I didn’t, but it took ages to work out.
    • There is a very cool trick to showing the microphone input visually using data-binding. If anyone is interested, leave a commend and I’ll post some source.
  • I really didn’t stick well to MVVM. Stuff such as telling the MediaElement to start/stop playing and switching on the microphone didn’t lend itself well to binding, and I was too sleep deprived to write behaviors. That would definitely be an improvement.
  • The marketplace submission failed twice; both times due to rules that require you play well with the rest of the phone (that’ll learn me to read the docs better):
    • You must be sure not to stop currently playing music without getting the user’s permission first. There’s a static property in MediaElement that allows you to check the current state.
    • You must get permission from the user before allowing your app to play music while the phone is locked.