Cross Platform Player in Android App

Building an Android app and don’t want to use the native MediaPlayer class? Check out IVA’s Cross Platform Player. This article will demonstrate how to use our player in an Android app using the Eclipse IDE and the Android SDK.

Within Eclipse click ‘File’ in the menu bar and create a’ New Project’ and give your application a name. When you reach the target SDK drop down select Android 2.3(Gingerbread) then hit next.

On the following screen you can add your app icon (optional: you do not have to have one). On the next screen you will define what Activity you want to use. In this example I will be using a Blank Activity. Hit next and then finish.

Now let’s create the Video Activity, click on your package name then New >> Other then type Activity. We’ll make this one a Blank Activity as well and we’ll name it VideoActivity. Make sure you update the activity’s layout name to “activity_video”.

>> Setting up the view and layout

Let’s work on the MainActivity’s view.  Open up res/layout/activity_main.xml and delete the TextView node and replace it with this:

<Button android:layout_width="wrap_content"
android:text="Play Video"
android:onClick="launchVideo" />


We’ve added an onClick attribute to the button, we’ll implement this method in the Here’s our method.

public void launchVideo(View v){
Intent intent = new Intent(this, VideoActivity.class);

>> Setting up the VideoActivity’s view.

The VideoActivity’s view will contain a webview node and we’ll remove the app’s padding so the view uses the full width and height of the screen. Replace the contents in activity_video.xml with

<RelativeLayout xmlns:android=""

<WebView android:id="@+id/webView"


Here’s the code for our

@SuppressLint("JavascriptInterface") @Override
protected void onCreate(Bundle savedInstanceState) {


Intent intent = new Intent(this, MainActivity.class);

WebView webview;

webview = (WebView)this.findViewById(;
webview.setWebChromeClient(new WebChromeClient() {

WebSettings webSettings = webview.getSettings();
webview.addJavascriptInterface(new JavaScriptInterface(this, intent), "jsInterface");


public String videoURL(int p_id, int c_id, int player_id, String sub) {
return "file:///android_asset/player.html?publishedid=" + p_id + "&customerid=" + c_id + "&playerid=" + player_id + "&reporttag=" + sub;

Something to note.

  • We’ve replaced the onCreate method
  • We’ve set this activity to be in landscape mode
  • We’ve set our settings for the player, in the loadUrl method.
  • We’ve created JavaScriptInterface  which will use JavaScript method calls to talk to our app. We’ll implement that below.

Add the JavaScriptInterface class within the VideoActivity class.

public class JavaScriptInterface {
Context mContext;
Intent i;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c, Intent _i) {
mContext = c;
i = _i;

/** Show a toast from the web page */
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();

public void goToMain() {


Before we can test our app, we’ll need to add the Internet permissions in the androidmanifest.xml
Here’s what that looks like:

<uses-permission android:name="android.permission.INTERNET" />

You can download the source for this app here.