How to play video from raw folder with Android device?

Please help,
How to play videos in android device from raw folder for offline mode?

Successful example1: I can play the video from SDcard used the below code.

  • Viewing private files created by an android app
  • Filtering ListView with custom (object) adapter
  • Android Soft keyboard action button
  • “Starting emulator for AVD” then Panic: could not open…"
  • Android transparent overlay toolbar
  • android what is the difference between Android Support Repository vs Android Support Library vs Google Repository vs Google Play Services
  •  Intent intent = new Intent(Intent.ACTION_VIEW);
     String type = "video/mp4";
     Uri uri = Uri.parse("file:///sdcard/test.mp4");
     intent.setDataAndType(uri, type);

    Failed example2:
    Question: May I put the test.mp4 to res/raw folder?

     Intent intent = new Intent(Intent.ACTION_VIEW);
     String type = "video/mp4";
     Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" +;
     intent.setDataAndType(uri, type);

    Have anyone can help me? Please.

    Related posts:

    Preemptive Basic Auth with HttpUrlConnection?
    Download App from Google Play programatically
    CharSequence to int
    Android Data Binding pass arguments to onClick method
    Make Tabs on ActionBar scroll when reach limit, rather than create a dropdown-list
    Google account authorization within an Android app
  • Couldn't read row 1, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it
  • How do I show an alert dialog only on the first run of my application?
  • actionbar search will not close after search
  • Unknown protocol error with HTTPS connection on android
  • Detecting the device being plugged in
  • Android preferences freeze when using ADT Plugin v9 with Eclipse on Mac?
  • 6 Solutions collect form web for “How to play video from raw folder with Android device?”

    Copy the video into your project’s res/raw folder. Create raw folder under res folder. It must be in a supported format (3gp, wmv, mp4 ) and named with lower case, numerics, underscores and dots in its filename likewise:video_file.mp4.

    VideoView view = (VideoView)findViewById(;
    String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;

    Create videoView in your xml file.

    Check this solution How to play videos in android from assets folder or raw folder?

    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
    // To get files from any resource folder (eg: raw, drawable, etc.)
    // Use the resource id
    int rawId = getResources().getIdentifier(file_name_without_extension,  "raw", getPackageName());
    // URI formation
    String path = "android.resource://" + getPackageName() + "/" + rawId;
    // Set the URI to play video file

    i think , everyone gave an answer, but doesn’t explain the scenario. The main problem here is, If im not mistaken , Android assume that the video coming from your SD Card is dynamic, where in it could be possible , that the format is not supported or supported, thus it enables / ask you to select or open for other third party media software.

    While anything you play UNDER RAW folder, requires a handler such as videoview or built in media player which leads to conclusion that anything you put in your RAW folder should be supported / readable by the Android OS.

    However , the thread starter here wants that his RAW files , to be played using a third party media player.

    I struggled with this for dynamic video names. The solution that worked for me was:

    //Somewhere set the video name variable
    String video+name="myvideo";
    //setup up and play video
    VideoView videoView=(VideoView)findViewById(;
    String uriPath = "android.resource://"+getPackageName()+"/raw/"+ video_name;
    Uri UrlPath=Uri.parse(uriPath);
    MediaController mediaController = new MediaController(this);
    videoView.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mediaPlayer) {
                if (position == 0) {
                    }catch (Exception e){
                        System.out.printf("Error playing video %s\n", e);

    And in XML

    <VideoView android:layout_width="300dp"

    This Solution will exactly helps you that what you want.

    VideoView myVideo;
    private MediaController media_control;
    protected void onCreate(Bundle savedInstanceState) {
        myVideo = (VideoView) findViewById(;
        Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.bootanimation_nexus);
        media_control = new MediaController(this);
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.