How to play video from raw folder with Android device?

android, android-layout, android-videoview

Solution

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();

Create videoView in your xml file.

Problem

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. ``` Intent intent = new Intent(Intent.ACTION_VIEW); String type = "video/mp4"; Uri uri = Uri.parse("file:///sdcard/test.mp4"); intent.setDataAndType(uri, type); startActivity(intent); ``` 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() + "/" + R.raw.taipei); intent.setDataAndType(uri, type); startActivity(intent); ``` Have anyone can help me? Please.

Original source

Related problems