Reputation: 29
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
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
Reputation: 16196
Please try this.
Uri uri = Uri.parse("android.resource://test.test.test/"+R.raw.[video_resid]);
v.setVideoURI(uri);
Upvotes: 2
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
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
Reputation: 12642
try Uri.parse("android.resource://test.test.test/" + R.raw.yourVideoName)
Upvotes: 1
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