How to play external video with java android jdk?
Here's an example on how to play video,
but it embeds the video as resource of the apk,
how to play an external video ,e.g. the test.mp4
under the /downl开发者_运维知识库oad
directory of sdcard?
You can use Video View Property to set an external Video
You can refer the below links
http://r00tsecurity.org/forums/topic/12059-android-videoview-example/
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/VideoViewDemo.html
path = "/sdcard/android.mp4";
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.start();
In this path, you can also set your path, e.g.
"/sdcard/download/android.mp4"
Videoview mVideoView = (Videoview) findViewByID(R.id.<your_videoview_id>)
file = "/sdcard/download/android.mp4";
mVideoView.setVideoPath(file);
mVideoView.setMediaController(new MediaController(this));
mVideoView.start();
Hope this will work.
Check and reply.
To open a file from say, the sdcard in android you use the getExternalStorageDirectory()
method that is defined in android.os.Environment
. Be sure to also check that an sdcard is available on the system first. You use the File object (it is a directory) returned from the getExternalStorageDir method to get the actual file and from that new file object (the actual file) you can call MediaPlayer.create with the uri of the actual file. Consider:
File dir = Environment.getExternalStorageDir();
File file = File(dir, "filename.mp4");
MediaPlayer player = MediaPlayer.create(context, file.toURI();
精彩评论