Search Engine

Thursday, December 16, 2010

Play Video From raw Folder In Android

Hello ,

This is the simple application for play video in android. This video play from raw folder.

And this are the simple of basic application .

And this are the source code for play video from raw folder.

First save video in res/raw folder. And then complete you code given below.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
<VideoView android:layout_height="fill_parent"

package com.image;


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

public class image extends Activity {
private static final String TAG = "PRANJAL";
private boolean isImage = false;
private String reviewImageLink;
private MediaController mc;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
VideoView vd = (VideoView) findViewById(;

Uri uri = Uri.parse("android.resource://" + getPackageName() + "Name OF Video store in raw folder");

mc = new MediaController(this);



I think u have useful this code.


Jazzie Casas said...

Java and to some degree .Net are the main choices because they have been consistently pegged as the “safe” choice to go with for mid-level project managers in the corporate world. No one was ever fired for choosing Java or Microsoft.

However, there are many large distributed applications these days that run primarily with technologies like Python, PHP, et al. Even companies like Google and Yahoo are heavily invested in these technologies. Java may be the main choice for enterprise development now, but it’s days are numbered as the only stalwart option to go with.

Let’s face it, many of these so called “enterprise applications” could easily have been written much faster and with less overhead using technologies like Python, PHP, et al.

ruby training

pankaj said...

good tutorial use
Uri uri = Uri.parse("android.resource://"+getPackageName() + "/";

Anonymous said...

I've tried every concievable method of playing a video. Used VideoView, MediaPlayer, MediaController, none of them seem to work seperately or in unison to play a raw file from a folder. This example also is not working for me. Still getting the typical "Sorry this video cannot be played message" I did at one point get a streaming video to not display this message, but it didn't play the video, only displayed a still image and audio.

Anonymous said...

just make sure to make the change pankaj said & it works perfectly!! :)
though, you dont need any of those private variables except for mediacontroller

so the steps are:
1) make sure you have a VideoView in your xml file (can leave the ID as VideoView)
2) in your java code, add a private global variable: private MediaController mc;
3) in the java onCreate method, add the following code:

VideoView vd = (VideoView) findViewById(;

Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video_name_without_file_extension);

mc = new MediaController(this);


surya said...

thanks a ton !!.. this really helped. esp the URI part ..
Thanks again

Raghav Rajagopalan said...

hi all!!!
Pls tell me wen i create a a folder called res/raw its getting saved in layout by default. is it correct. and i cannot open the raw folder to add video. what type of videos can i play(mp4,flv...).

secondly i need a code to record a video and save it. pls help me in developing this application in android. I shall be very much thankful to u!!!
pls reply me asap since i need to finish this work by monday!! Sorry if i am pressuring you.

Thanks in advance.

Raghav Rajagopalan

Raghav Rajagopalan said...

hey!!! Thanks it worked perfectly for me!!! Any way thanks for the tutorial!! All the best!!! Thanks once again..

usman said...

doesnt work with assets.

Vinay Julme said...

Hi, I'm still facing a problem and it is that the audio is working fine but not the video. Its an mp4 file.

Naveen Kumar shrivastva said...

Hello someone,

Please help me how to play large video in android.

i want to play 1Gb video from sdcard facing outof memory exception.Please help me, My work is delay due to this.

sawan Modi said...

hello Naveen Kumar,

Please upload this video on your server. And this URl put on your application.

Its easy way for used any video.

Naveen shrivastva said...

Dear sir,

Here i know i am able to play large video from server through uri instance.But i my objective is play video from sdcard any how?

Please help me sir and share me your ideas


sawan Modi said...

hello Naveen Kumar,

You have to play video from SDCard.

SDCard path will be used on this Application.

I think its better for you


Shubham said...


subrat said...

I cant play the .3gp video file in my emulator.I hav used the above code. I dont know why its not working ? I am getting msg as "sorry this video cant play" . I have used:
mVideo = (VideoView)findViewById(;
Uri path = Uri.parse("android.resource://"+getPackageName()+;
mc=new MediaController(this);

Golubov Csaba Antal said...

subrat: you forgot about the "/" in front of

Anonymous said...

Thanks to all! It works;)

Irei te ajudar said...

Thanks for your help!

It worked with the code below.

Uri uri = Uri.parse("android.resource://"+getPackageName() + "/";

Anonymous said...

Thank you. This was the missing link for me. Really helpful code sample.

Uri uri = Uri.parse("android.resource://"+getPackageName() + "/";

lifesmith said...

Thanks a bunch. It worked when I used
Uri uri = Uri.parse("android.resource://"+getPackageName() + "/";

sujal said...

Uri uri = Uri.parse("android.resource://"+getPackageName() + "/";
hey this is not working for me....
its giving file can not play again and again...
i have created raw folder inside res and saved the video having file extension mp4. please tell me the fault...

Anonymous said...

yes, it's working fine for me... Thank for this post, it was very helpful...

MKMA said...

can the owner of the post incorporate the comments and make the original post error free?
also i can hear audio, but cannot see video for mp4 file, with above code.
same file plays fine on windows with vlc.

Nikunj said...

Hello Sir,
Your code it working but i can't see the video only listing the audio.
please sir help me

mp4 format to mov mac said...

Hi, I'm still facing a problem and it is that the audio is working fine but not the video. Its an mp4 file.

Anonymous said...

not working

Anonymous said...

Not working!!! I have error "Sorry, this video cannot be played". Please, help me!

Pope said...

I just solved the "Sorry, this video cannot be played" by a simple stupid mistake I had not looked at keenly. I had left the in double qoutes. so "" doesnt work. Problem of just copying and pastig....lolest.....

Anonymous said...


best keylogger software said...

hi there, there are many free video converters on the web. just google it you will find many great result.

Anonymous said...

why my vidio only sound and the screen only black not a picture???

Anonymous said...

Your code it working but i can't see the video only listing the audio.
please sir help me

kelvin ricafort said...

how to play videos if the video view is on another activity?

Akula Kishore said...

Thanks for u r valuable tutorial......
its working

Maribeth Butac said...

Thanks! this tutorial helps a lot. had a problem in playing video it says "can't play video" but I realized I saved a zipped .mp4 file in raw :P .. so I extracted it and save unzipped file.. and it works .. thanks!

abettersoft said...

The method is great, but I think you can convert the raw video to other formats to replay. I have been using abettersoft to convert avi to mov on Mac for enjoy on pc, here is detailed guide: It can rip DVD to AVI, MP4, MOV, MKV, WMV, DivX, XviD, MPEG-1/2, 3GP, 3G2, VOB… video formats. have a try.

videotool said...

Post is nicely written and it contains many good things for me. I am glad to find your impressive way of writing the post. learn more about convert mts to mov on mac at

Anonymous said...


Anonymous said...

hi I tried everything that is written but I can't find the application when playing it in the emulator it says, [2013-12-28 22:23:30 - Video Testing] emulator-5554 disconnected! Cancelling ' activity launch'! and the emulator disconnects

I don't know what the problem is, can you guys help me :(

Anonymous said...

how does the video view become full screen. I keep getting a half screen video view.

kevin james said...


Anonymous said...

it worked few days ago but suddenly it says that"can't play video" i checked everything but can't seem to find the problem.what do you guys think the problem is?i badly need to fix this thank you.

a Ba said...

VideoView videoHolder = new VideoView(this);
//if you want the controls to appear
videoHolder.setMediaController(new MediaController(this));
Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.your_raw_file); //do not add any extension
//if your file is named sherif.mp4 and placed in /raw
//use R.raw.sherif

Post a Comment