Background Music Queue with AVPlayer and iOS4

Update 2010-Nov-11: Apple has come out with AVQueuePlayer in iOS 4.1, and presumably most people are going to move to the latest version now that it performs well even on the 3G, but the AVPlayer can still be used to manually create a queuing of items, but if you want all the hard work to be done for you, with only a few limitations, then use AVQueuePlayer instead.

Update 2010-Oct-19: Apple has been updating their documentation slightly, and it has more information now with regard to setting up an asset. This is more specifically for video, but it might help fill in the blanks for just audio. AVPlayer Playback Guide

The iOS 4.0 framework introduced AVPlayer which allows playing a MP3s from the iTunes Music Library in the background without using the iPod music player. This has a couple benefits over the MPMusicPlayerController in that you can add new items, stop, or play music in the background. Also, a custom icon can represent your app in the multitasking menu where the ipod controls are located. If you stick with [MPMusicPlayerController iPodMusicPlayer] you can play music in the background through the ipod player, but once an app goes into the background, it no longer has control over the playback of the music.
Continue reading

How To Securely Manage Your Online Identity

Today we use hundreds of websites on a daily or weekly basis. Many of these require us to create and login with a password. Over time managing all of your identities is a serious challenge. I have decided to give an initial look at the problems and some solutions that you are likely already using to help in this regard.

Problem with Passwords

We’re Human


People use simple passwords that are common words, names, or are patterns of keys such as ‘qwerty’ or ‘asdfasdf’ because they are easier to remember. Many people also use a small number of passwords to login to hundreds of websites that they visit each day. I would also guess that many people use the save password feature with their browser in order to save from typing their passwords in each time they visit a site that requires it. Anyone can walk up to your computer and login to any website for which you have a saved password. So we use simple passwords, and reuse them, and store them in our browsers. How can we prevent ourselves from this inherently insecure behavior?

How secure is your password? Find out.

Continue reading

Random ‘Draw’ With Shuffle

While writing Naval Fight I wanted to have the easy computer opponent select a random position on the board grid every turn.

First I implemented a naive solution creating an array of all possible positions that would be randomly selected from, but after a selection was used it was removed from this array.

validPositions = gridPositions.clone();

// selection
position = validPositions[random() * validPositions.length];

This solution was adequate, but there can always be improvements, and now that I am storing information in a second array, how can it be used more efficiently. Thinking about the problem further it became apparent that this was akin to listening to a playlist on shuffle. Which then gives the light bulb moment that instead of thinking about random selection with no repeats I should just shuffle the array of positions, just like having a deck of cards and removing a card for each turn, noting it’s value (ie: grid position).

After a little searching I came across the Fisher-Yates shuffle algorithm, and found an efficient and unbiased implementation:

// setup
int currentPosition = 0;

for (int i = gridPositions.length; i > 1; i--) {
  // Pick a random element to swap with the i-th element.
  int j = uniform_random() * i;
  // Swap elements.
  int tmp = gridPositions[j];
  gridPositions[j] = items[i-1];
  gridPositions[i-1] = tmp;

// selection on each turn
position = gridPositions[currentPosition++];

This solution generates an array of possible positions which are then shuffled, and finally an index into the array is stored where the next position can be read. Each time the position is accessed from the array this counter increases to always point at the next position. There are other solutions that would work, but this seems to be a good final solution for my problem.


Listen to Your Passion

What’s your passion? What do you find interesting? Funny? Inspiring? There is very likely an audio or video show out there with your specific interests in mind. Podcasts – as they are usually referred to – can be found by searching the iTunes Store, Zune Social, Miro Guide, or just a generic search on your favorite trusty search engine. You can then download and listen (or watch) these shows on your commute, while working out, or traveling. I mostly enjoy learning about my trade – technology and programming – but also enjoy keeping up with sports, news, and the economy, as well as having a good laugh or two. I find it difficult to choose which podcasts to listen to since there’s only so much time in the day, and while it’s great to constantly learn, at some point you have to make your own contribution using the knowledge gained from listening and apply it to your own projects and life.

The following is a list of many of the shows that I tune into. Some I listen to weekly, but most of them I only listen to the episodes that interest me. I find podcasts are especially beneficial for when I’m working out and traveling, and if you have a long commute I’d imagine they’re a lifesaver.
Continue reading

iPad – It’s Just A Big iPhone

The Larger Screen Matters

Ever since watching the first Harry Potter movie, I’ve been fascinated with the idea of having newspapers with video and continually updated content. I have always hoped that someday we would have the same experience, and the iPad is the first gadget to finally succeed in bringing us this reality. After using the iPad for a few months now, I think that it is still a luxury consumption device that could definitely fit between the laptop and phone markets. It really is just a larger iPhone, and with similar resolution to the new iPhone 4 Retina Display ™, but it’s amazing how having a larger form factor makes apps and games so much more enjoyable to use. While it is currently meant for consuming content, the addition of a bluetooth keyboard and more powerful apps will allow for creating content such as drawing, composing music, documents, presentations, and writing screenplays as just a few examples.

While it can replace the Amazon Kindle for most people, I still enjoy reading on the Kindle due to it being very light to hold, and it’s excellent for reading in bright sunlight. But, if you only want to buy or carry around a single reading device, then the iPad is definitely the device to have. It is a great replacement for reading books, magazines, newspapers, and cookbooks. It works very well as a PDF reader, especially with the new support in the Apple’s official e-reader app iBooks. It can also be used for playing games, watching movies, viewing photos, browsing the internet, looking at maps, and much more.

Continue reading