Pages

Subscribe:

Labels

Wednesday, 28 September 2011

Android Video Playing from Url

This code snippet is used to demonstrate the video plying.

The MediaController  of the VideoView will call the hide method at every 3 sec to hide the controller bar.If you don't want to hide the controller then override the hide method.That's what i done in my example.

 The layout file is as follows video.xml

 <?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"
    >
    <VideoView android:id="@+id/videoView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </VideoView>
</LinearLayout>



 Also requires the permission to access the network

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

 And the java code is like this

 package com.video.tab;


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


public class VideoPlayActivity extends Activity {
   
    public void onCreate(Bundle bundle){
        super.onCreate(bundle);
        setContentView(R.layout.video);
        VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
        final MediaController mc = new MediaController(this);
        videoView.setMediaController(new MediaController(this){
            /*public void hide()
            {
                mc.show();
            }*/
        });
       //videoView.setVideoURI(Uri.parse("http://www.androidbook.com/akc/filestorage/android/documentfiles/3389/movie.mp4"));
     videoView.setVideoPath("/sdcard/rabbit-and-snail.3gp");
       videoView.requestFocus();
       videoView.start();
       


    }


}

No comments:

Post a Comment