Pages

Thursday, May 20, 2010

Android play video without controls



  • Here we are going to play a 3gp video in our Android application.



  • The important point we have to note is that video doesn’t plays when placed in the raw folder.Hence it has to be placed in the SDCARD itself.
    So lets begin this interesting topic.
    Ok, let us first insert our video:


    • You can get a short 3gp video from net (I got it from http://www.free-3gp-video.com).


    • In eclipse open perspective DDMS(Window –> Open Perspective –> DDMS) .


    • In DDMS perspective open view File Explorer(Window –> Show View –> File Explorer).


    • Also open Device view (Window –> Show View –> Device) and click the emulator you want to use(if emulator is not running then run a emulator with a sdcard option).


    • Then in File Explorer view navigate the tree shown and click sdcard node.


    • There are two buttons on the top right hand side of File Explorer as shown below







      • Click the button “Push a file onto the device” and in the file chooser navigate and choose the 3gp video.It should appear in the list of sdcard.(If not able to insert, check whether SDCARD is emulated in the emulator , in 1.5 sdk while creating a new Emulator there is a option of sdcard , insert 128M in the textbox next to it).


      • Ok, back to our code, open java perspective(Window –>Show View –> Java) and open layout file Main.xml.
    Replace the its content with following contents:
    ( I will use "(" in place of  "<" )
    **********************************************
    (?xml version="1.0" encoding="utf-8"?>
    (FrameLayout android:id="@+id/FrameLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    (VideoView android:id="@+id/myvideo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    (/VideoView>
    (/FrameLayout>

    **********************************************
    Marie Claire (2-year)
    • Now create your main activity class :


    public class SeeVideo extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         // set the view to our layout file

         setContentView(R.layout.main);
         // Video view: to view our video
         VideoView video = (VideoView) findViewById(R.id.myvideo);

         //set your video path(in this case squirrel-playing-football.3gp)
         video.setVideoPath("/sdcard/squirrel-playing-football.3gp");
         video.start();
        }
    }
    *********************************************

    • Run the application and the video runs as shown below:


    No comments:

    Post a Comment