Friday, June 3, 2011

how to open video in android?

main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingLeft="2px" android:paddingRight="2px"
    android:paddingTop="2px" android:paddingBottom="2px"
    android:layout_width="fill_parent" android:orientation="vertical">

    <VideoView android:layout_height="fill_parent"
        android:layout_width="fill_parent" android:id="@+id/VideoView"></VideoView>

</LinearLayout>


.java file

package com.videoplayer;

import android.app.Activity;
import android.media.MediaRecorder.VideoSource;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class videoplayer 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.VideoView);
       
        MediaController mediaController=new MediaController(this);
        mediaController.setAnchorView(videoview);
       
      
        Uri video=Uri.parse("MP4 VIDEO LINK");
        videoview.setMediaController(mediaController);
        videoview.setVideoURI(video);
        videoview.start();
    }

   
}

No comments:

Post a Comment