所以我试图设置一个活动,用户可以在其中浏览他各自存储中的视频,然后使用 VideoView 播放它。我怎样才能做到这一点?我在下面写了一些代码。
另外我使用的是 Nexus 7,所以它没有 SD 卡。如何制作通用代码以从内部/外部存储器中获取视频?
public class VideoCapture extends Activity {
private static final int INSERT_ID = Menu.FIRST;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.gc();
String filename = "/sdcard/Video/sample.mp4";
//String fileName = "android.resource://" + getPackageName() + "/" + R.raw.sample;
VideoView videoView1 = (VideoView)findViewById(R.id.videoView1);
setContentView(videoView1);
videoView1.setVideoPath(filename);
videoView1.setMediaController(new MediaController(this));
videoView1.requestFocus();
videoView1.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, INSERT_ID, 0,"FullScreen");
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case INSERT_ID:
createNote();
}
return true;
}
private void createNote() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}