Adding Video

Playing videos during games is unusual, but they have a very important purpose in introducing games or prior to each level. Fortunately, videos are handled pretty much identically to music and other audio. In fact, to test a video, you can replace the .mid file with a .3gp file. Then, when the surface is created, the video will play.

Doing a quick Internet search for 3GP videos offers a plethora of options. If you have music videos in the .mp4 format, you can also add those to your raw resource folder. Listing 4-5 contains the code used for playing one of these files.

Listing 4-5. Playing a Video

@Override public void surfaceCreated(SurfaceHolder holder) {         mGameLogic.setGameState(mGameLogic.RUNNING);         mGameLogic.start(); ...

Get Beginning Android Tablet Games Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.