Uw betrouwbare partner voor (mobiele) web applicaties
TwitterEmailRSS

Game TV

I’ve been wanting to create a mobile videogame-focused app for a looooooooong time. During the Christmas break I finally has some spare time and created…: Game TV  😛 😮 🙂   sorry, can’t stop smiling

Game TV.. wut?

So what is it? By installing Game TV the user will always know which channel (game related websites or youtube channels, to be precise) has added new content. By clicking the channel, the user will see a list of recently added video’s and is able to play the video and share it with friends (email) or the world (twitter). Game TV doesn’t bother you with registration or advertisements, just pick and play!

Game TV at a glance

Technique

Well, we’re all techies here, right? So let’s highlight some technical bits.

Client

 PhoneGap / Cordova wrapped JQuery Mobile app (css3, html5, js). Kindly built by PhoneGap build. Notable stuff:

– Responsive design with CSS3 is cool. See the upper left screenshot in the pic above. This is how I position the video (block a) next to the description (block b)  when in landscape, or above the description when in portrait orientation (default JQM width of these blocks is 50%):

@media all and (orientation:portrait) {
  #videoplayer .ui-block-a, #videoplayer .ui-block-b {
    width: 100%;
  }
}

– As the app will *cough* obviously hit 100.000+ users shortly, clientside caching is very important. We cache the channels and videos in sessionstorage. But to guarantee a quick startup, we also leverage localstorage. When the app is started, the content is immediately retrieved from localstorage and asynchronously updated from the server, showing the diff to the user when done (red  count bubbles, we all know them).

– Since I want my app to be present in all appstores, I had to localise some bits of text. Keith Wood has created a simple yet very effective jquery localisation library.

Server

Play! Framework Java app, doing two things:

– Harvesting new content for all channels. 1 Job per channel.

– Serving the harvested content as JSON to the client.

What I’ve learned

– Android and iOS have great native videoplayers, as long as you invoke them correctly.

– Android animations are still not as smooth as on iOS. Fortunately, JQuery Mobile allows you to easily configure them per platform. I used this snippet:

// override some defaults, before jqm.js is loaded
$(document).bind("mobileinit", function(){
  $.mobile.defaultPageTransition = isAndroid() ? "fade" : "slide";
});

– Adding a Tweet button with a count bubble (see the upper left screenshot in the image above) is not as trivial as you’d think when you don’t want users to leave your app while tweeting. A combination of clickjacking, Twitter web intents and the PhoneGap Childbrowser plugin did the job.

– Some sites make life for a screenscraper really hard. Try to find the URL of the videos being played on this site for example. Horror!

– .. but YouTube rocks, thank you for providing easily parseable RSS feeds like this one (Gamespot channel).

– JQuery Mobile is great, but has some nasty caveats (stacking click handlers, document ready, reloading a page, etc). We’ll definitely blog about some high and lows of JQM in the future, but for now: download the Android app please please please 🙂There will probably be no iOS version because of the strict Apple review guidelines regarding streaming ‘protected’ content.

Prevent your Heroku Play! apps from idling

Disclaimer: we understand that the following may be a teeny weeny bit disrespectful to the free service Heroku provides, but asking $35/month is a bit steep for a website with less than 24 requests per day. If it gets popular some day, we will ofcourse reconsider our strategy.

While looking for a cloudservice to host our libwat.ch Play! (Java) app, we stumbled upon Heroku.com. It’s a really nice service which supports all kinds of (free and paid) configurations.

Cheap Dutch basterds as we are, we wanted the free service -so that means 1 webworker which falls asleep after an hour of inactivity. The app isn’t that popular yet (c’mon, sign up!), so it dozes off very frequently.

This means the request (person) that awakes the app must wait some 20 seconds while the app steps out of bed, brushes its teeth and combs its hair… not good!

Fortunately, only the webworker is put to sleep, so any background jobs are never idled, which leaves us with a nice opportunity to insomnatise the webworker 🙂

Just add this job to your Play app* :

@Every("55min")
public class KeepSiteAwakeJob extends Job {

  @Override
  public void doJob() throws IOException {
    new URL("http://libwat.ch").getContent();
  }

}

*) Note that if you’re not using Play!, you could still use one of the free scheduler plugins Heroku offers and have that invoke the website every sub-60 minutes.

Asynchronous jobs with Play Framework

Ever needed to run some standalone asynchronous job from Java and found it to be a bit tedious? Read on..

Declaring a Job in Play that runs every 3 seconds  and increments a property is as simple as this:

@Every("3s")
public class PublishJob extends Job {

  private int i;

  @Override
  public void doJob() throws Exception {
    i++;
  }
}

Q: W00t! It can’t be that simple!
A: Sorry, it really is.