Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play videos from SD Card

I was creating a simple app which stream videos from net and I made it but now I want to change the code so that I can play video files from my SDCard

original code:

Uri vidFile = Uri.parse("MY SITE HERE");
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setVideoURI(vidFile);
videoView.setMediaController(new MediaController(this));
videoView.start();

So please help me with changing the code so that it can play videos from my mobile memory card.

like image 515
Mohit Avatar asked Jun 03 '12 11:06

Mohit


People also ask

How do I watch videos on my SD card?

How can I view the video recordings of camera from the SD card on a computer? Please plug the SD to your computer's SD card slot or an SD card adapter. If you are using the SD card adapter, please insert it into a USB port on your computer.

Why won't my SD card play videos?

If you are unable to play videos saved on the SD card of your device, ensure, your SD card is not loose and is correctly inserted in your phone. So, check the SD card and make sure it is locked in its place.


3 Answers

The videoView.setVideoURI(vidFile); method needs to be replaced by the videoView.setVideoPath(path); method. Here path specifies the path of the video file on the SDCARD.

This path can be easily retrieved using the MediaStore.Video.Media.DATA property of that video file or by just entering the songpath statically as /sdcard/songname.

like image 97
Anurag Ramdasan Avatar answered Oct 17 '22 19:10

Anurag Ramdasan


Uri vidFile = Uri.parse(
   Environment.getExternalStorageDirectory().getAbsolutePath()+"filename");
... 

the rest of the code will be same.

like image 38
Ronnie Avatar answered Oct 17 '22 20:10

Ronnie


In place of

videoView.setVideoUri(vidFile)

use

videoView.setVideoPath("/sdcard/SONG.").

Let me know.

like image 1
Eight Avatar answered Oct 17 '22 19:10

Eight