Developing Video Player for Android

One of the issues you may face when developing an application for Android is embedding of a video player into your application. A standard SDK provides two ways of solving this problem. You may use a low-level MediaPlayer class or a ready visual VideoView component in conjunction with MediaController, a standard playback control panel. Both approaches have their downsides, so we decided to develop our own video component, AVideo. In this post, we will discuss how you can use this component in your application and what are its benefits.

First of all, let’s mention shortcomings of the standard class. Well, MediaPlayer is a low-level class. So it offers the maximum capabilities, but still it is too complex to be used directly. To hide complexity of the MediaPlayer from the developer, SDK offers the VideoView class. Below is a simple program based on VideoView and MediaController:

However, the VideoView class is suitable only for the simplest applications. It is not so easy to add new functionalities or even re-design playback panel controls, as this is not supported by the SDK. Developers can only implement their own MediaPlayer-based component from scratch or cut and paste the needed components from the publicly available Android sources and make necessary changes. That’s what we have done when developing our AVideo player. As a result, we obtained a set of video classes which are compatible with the standard interface, but additionally implement the following functionality:

Modified design of video playback panel controls.

Volume control and mute button.

Screen backlight brightness control.

Correct operation of the component and its controls within a complex layout, when the video is only part of the screen.

Layout toggling between normal and full-screen display by double-click, with changing of size of the playback panel controls.

Pausing and resuming playback, with restoring the current position after the device screen has turned off or application has quit.

Our video components are easy to use. Download the archive with the source and samples from github.com. Import projects from the archive to the Eclipse workspace and add them to your application as libraries (Project Properties, Android, Library, Add …). The code of a simple video player based on these components will be exactly the same as with the standard components. Only class import lines will change. Also, in the layout file, our package ru.denivip.android.video will be added to the VideoView component name. Here is a simple layout code: