Sunday, September 28, 2014

how to play video in android programmatically

MAIN.XML should be like this-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<VideoView
android:layout_height="wrap_content"
android:id="@+id/videoView1"
android:layout_width="match_parent">
</VideoView>
</LinearLayout>

VIDEOPLAYERACTIVITY.JAVA-
package com.example;

import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class VidePlayerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        VideoView videoView=(VideoView)findViewById(R.id.videoView1);
        videoView.setVideoPath("sdcard/Padaiyappa - minsara poove.mp4");
        MediaController mediaController=new MediaController(this);
        videoView.setMediaController(mediaController);
    }
}
 
 THIS IS A SIMPLE EXAMPLE.IT IS JUST TO GUIDE YOU