Search code examples
androidvideoandroid-videoview

Android: how to play video from assets?


I am making an application in which I have to show video from assets folder in a Fragment. Can anyone help me do this? Do I need to use VideoView in XML?


Solution

  • Instead of accessing from assests,You must 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(R.id.videoView);
    String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
    view.setVideoURI(Uri.parse(path));
    view.start();