O'Reilly logo

Beginning Android Tablet Games Programming by Jeremy Kerfs

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required