Monday, June 18, 2012

How To Play Video File In Android

This is a sample activity which shows How to run a video file.
Underlying Algorithm:
Basic description of algorithm in step by step form:
1.) Create a Project VideoViewExample.
2.) Put a video file in raw folder and keep it inside the res folder.
3.) Put the following code snippet in main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

4.) Run the application.
Steps to Create:
1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. VideoViewExample. Enter following information:
Project name: VideoViewExample
Build Target: Google APIs
Application name: VideoViewExample
Package name: com.sample.VideoViewExample
Create Activity: VideoViewExample
On Clicking Finish VideoViewExample code structure is generated with the necessary Android Packages being imported along with VideoViewExample class will look like following:
package com.sample.VideoViewExample;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class VideoViewExample extends Activity {
   private VideoView mVideoView;
   public void onCreate(Bundle icicle) {
     mVideoView = (VideoView) findViewById(;
     mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName()+"/"+R.raw.documentariesandyou));
     mVideoView.setMediaController(new MediaController(this));
Output –The final output:

No comments:

Post a Comment