3

I want to play a video from res/raw in android here is my code:

public class CreditsActivity extends Activity{

    @Override
     protected void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.creditslayout);
            VideoView v = (VideoView) findViewById(R.id.video);
            v.setVideoURI(Uri.parse("android.resource://test.test.test/raw/maincredits"));
            v.start();
    }
}

But I hear only the sound of video. And the emulator doesn't show the video itself the size of file is 2.8 MB.

Roan
  • 1,200
  • 2
  • 19
  • 32

6 Answers6

3

Try below code :

public class CreditsActivity extends Activity{

        @Override
         protected void onCreate(Bundle savedInstanceState){
                super.onCreate(savedInstanceState);
                setContentView(R.layout.creditslayout);
                VideoView v = (VideoView) findViewById(R.id.video);
                v.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video_file));
                v.start();

    }


}
Dinesh
  • 6,500
  • 10
  • 42
  • 77
2

Please try this.

Uri uri = Uri.parse("android.resource://test.test.test/"+R.raw.[video_resid]);    
v.setVideoURI(uri);
Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
Nikhil
  • 16,194
  • 20
  • 64
  • 81
1

try Uri.parse("android.resource://test.test.test/" + R.raw.yourVideoName)

Mohsin Naeem
  • 12,542
  • 3
  • 39
  • 53
1

Try this

       // trailer_final is the video name

      String fileName = "android.resource://"+ getPackageName()+"/raw/trailer_final";

      VideoView mvideo = (VideoView) findViewById(R.id.playVideo);

      mvideo.setVideoPath(fileName);

      MediaController controller = new MediaController(this);

      mvideo.setMediaController(controller);

      mvideo.requestFocus();

      mvideo.start();
moDev
  • 5,248
  • 4
  • 33
  • 63
0

Try this:

VideoView view = (VideoView)findViewById(R.id.videoView);
String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
view.setVideoURI(Uri.parse(path));
view.start();

Just pass the name of the video residing in the raw folder under res of the project.

AkashG
  • 7,868
  • 3
  • 28
  • 43
  • check this out-http://stackoverflow.com/questions/11356601/androidplay-video-from-assets/11356700#11356700 – AkashG Jul 12 '12 at 12:40
0

The emulator doesn't show the video. I had this problem on a project. We tried it on an actual device and it played perfectly. Try to play it on actual device. It will likely work.

Pankaj
  • 327
  • 3
  • 14