问题
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.
回答1:
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
.
回答2:
Uri vidFile = Uri.parse(
Environment.getExternalStorageDirectory().getAbsolutePath()+"filename");
...
the rest of the code will be same.
回答3:
In place of
videoView.setVideoUri(vidFile)
use
videoView.setVideoPath("/sdcard/SONG.")
.
Let me know.
回答4:
these links may help you:
Playing 3gp video in SD card of Android
how-play-video-and-audio-android
Using VideoView to play mp4 from sdcard
回答5:
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.
来源:https://stackoverflow.com/questions/10869830/how-to-play-videos-from-sd-card