如何从android中的原始文件夹运行视频?

时间:2013-07-15 12:37:30

标签: android android-videoview

我试图在原始文件夹中运行视频,只关注此问题How to play a local video from resources folder 但它对我不起作用。 我的视频格式是.m4v。如何在android中运行.m4v格式的视频?

3 个答案:

答案 0 :(得分:2)

VideoView videoview = (VideoView) findViewById(R.id.videoview);
videoview.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video));
videoview.start();

不支持.m4v格式,此处为the official list of supported video formats。您必须将视频转换为支持的格式。

答案 1 :(得分:0)

private VideoView vd; / class variable

vd = (VideoView) findViewById(R.id.videoview);

playVideo();

playVideo()方法

Uri uri = Uri.parse("android.resource://" + getPackageName() +"/"+ R.raw.ur_videoFile_name); 
vd.setVideoURI(uri);
//MediaController mc = new MediaController(this);
//vd.setMediaController(mc);
vd.setMediaController(null);
vd.start();

答案 2 :(得分:0)

String videoSource = "android.resource://"+getpackageName()+"/raw/"+videofile name w/o file extension;
VideoView myVideoView = (VideoView) videoView
                                .findViewById(R.id.myvideoview);
myVideoView.setVideoURI(Uri.parse(videoSource));
myVideoView.setMediaController(new MediaController(MyActivity.this));
myVideoView.requestFocus();
myVideoView.start();

这才有效!