Home > Android > Play Video

Play Video

August 18th, 2009

Hello,

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

push a video onto the sdcard

push a video onto the sdcard

  • 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:

<?xml version=”1.0″ encoding=”utf-8″?>
<FrameLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<VideoView
android:id=”@+id/myvideo”
android:layout_gravity=”center”>
</VideoView>
</FrameLayout>

  • Now open your main activity and insert the following in the onCreate method as:

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 video path to our video(in this case man-cheetah-gazalle.3gp)
video.setVideoPath("/sdcard/man-cheetah-gazelle.3gp");
video.start();

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

Video snapshot

Video snapshot

Android , , , , , , , , , , ,

  1. ClaveMartin
    October 15th, 2009 at 14:34 | #1

    I tried the samething but i couldn’t make it work. And i couldn’t set my emulator as sdcard node as well. I don’t know how to make sdcard node for emulator.

  2. Jorgesys
    October 28th, 2009 at 17:29 | #2

    Hi ClaveMartin, use the command “mksdcard”

    usage::
    mksdcard -l “label” “size”"M for MB or K for KB” “file”
    example:: mksdcard -l sdcard 200M C:\Android\SDCARD\img200jorge.img

    :)

    p.d. this is the correct one (this post filters the characters “”:(

  3. Zeba
    November 6th, 2009 at 00:56 | #3

    Hi,
    Can we have play , pause n stop buttons for the Video View ???
    N can dis be used for 3gp videos only???
    I wanted to play .wma and .mp3 videos…. how do I do dat??
    Thank you.

  4. December 15th, 2009 at 08:24 | #4

    hi all,

    you’re not limited to the SD card, you can also play videos bundled with your app, just place it in the assets folder instead of the raw folder.

  5. December 15th, 2009 at 08:29 | #5

    hi all,

    you’re not limited to the SD card, you can also play videos bundled with your app, just place it in the assets folder instead of the raw folder.

  6. jetti
    February 13th, 2010 at 07:04 | #6

    Hi to all,
    I executed this program and works fine but i want to play an video repeatedly infinite times and also until some condition matches…..
    Please help on this…..

  7. Jui Bhatt
    February 18th, 2010 at 05:18 | #7

    Hello,

    Thanks a lot for this blog.
    But i think it is important to know that through this program video is played on platform 1.5 but not on 2.0 and 2.1.

  8. Lalitendu
    February 25th, 2010 at 06:32 | #8

    Hi,

    I tried this. It’s working fine. It helped me a lot

    Thanks

  9. sujit
    July 8th, 2010 at 23:03 | #9

    Hello,
    I tried this on 2.0 and it is working fine but in 1.5,2.1 it is not working.And also my video is not full screen though i have set the width and heigh of VideoView to “fill_parent” .

    Thanks.

  1. No trackbacks yet.