14

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.

yorkw
  • 40,926
  • 10
  • 117
  • 130
Mohit
  • 1,045
  • 4
  • 18
  • 45

6 Answers6

13

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.

Anurag Ramdasan
  • 4,189
  • 4
  • 31
  • 53
  • hey what about Uri vidFile = Uri.parse("MY SITE HERE"); correct me if i am wrong but there is no need of this so i should just delete it? – Mohit Jun 03 '12 at 16:38
  • btw will it only play .3gp files or it depends on formats supported by my mobile? – Mohit Jun 05 '12 at 03:24
6
Uri vidFile = Uri.parse(
   Environment.getExternalStorageDirectory().getAbsolutePath()+"filename");
... 

the rest of the code will be same.

Ron
  • 24,175
  • 8
  • 56
  • 97
  • its got a filename for a specific video file, what if i want to select from a list, how to play the SELECTED video file? – Mohit Jun 03 '12 at 11:29
  • the example code above assumes the file is at the root level.. you can append the /path/filename.mp4 to the path returned by `getabsolutePath()` – Ron Jun 03 '12 at 11:36
1

In place of

videoView.setVideoUri(vidFile)

use

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

Let me know.

Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69
Eight
  • 4,194
  • 5
  • 30
  • 51
0

I also tried your code and got same error message but when I tried with video path with no blank space in path or name, it worked well. Just give it a try. e.g, file path "/mnt/sdcard/Movies/Long Drive Song - Khiladi 786 ft. Akshay Kumar_Asin-YouTube.mp4" gave the error but file path "/mnt/sdcard/Movies/Khiladi.mp4" worked well.

user1653781
  • 69
  • 1
  • 6
0

I know is is old but if it can help. add this to your manifest

<uses-permission android:name="com.android.externalstorage.ExternalStorageProvider"/>