Mohammad Mobayen
Mohammad Mobayen

Reputation: 29

android play a video from res/raw

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.

Upvotes: 3

Views: 9174

Answers (6)

Pankaj
Pankaj

Reputation: 327

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.

Upvotes: 0

Nikhil
Nikhil

Reputation: 16196

Please try this.

Uri uri = Uri.parse("android.resource://test.test.test/"+R.raw.[video_resid]);    
v.setVideoURI(uri);

Upvotes: 2

moDev
moDev

Reputation: 5258

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

Upvotes: 1

Dinesh
Dinesh

Reputation: 6532

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

    }


}

Upvotes: 3

Mohsin Naeem
Mohsin Naeem

Reputation: 12642

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

Upvotes: 1

AkashG
AkashG

Reputation: 7888

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.

Upvotes: 0

Related Questions