コードから ViedoView を作成しようとしましたが、実行すると作成されたビューが表示されません。ビデオのパスをDBに保存してから、表示しようとしています。私はImageViewとその作品で同じことをしようとしているので、VideoViewで何かを忘れていると思います。
私のコード:
private void getUserVideo() {
Intent intentToPlayVideo = new Intent(Intent.ACTION_VIEW);
intentToPlayVideo.setType("video/*");
intentToPlayVideo.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intentToPlayVideo, SELECT_VIDEO);
}
public void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(
selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
extras = getIntent().getExtras();
String s = extras.getString("date");
DataBaseMain data = new DataBaseMain(this);
data.open();
data.putWorkOutPic(filePath, s);
data.close();
recreate();
}
case SELECT_VIDEO:
{
if(resultCode == RESULT_OK){
Uri vid = imageReturnedIntent.getData();
String videoPath = getRealPathFromURI(vid);
extras = getIntent().getExtras();
String s = extras.getString("date");
DataBaseMain data = new DataBaseMain(this);
data.open();
data.putWorkOutVideo(videoPath, s);
data.close();
recreate();
}
}
}
}
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
private void addVideos() {
extras = getIntent().getExtras();
String s = extras.getString("date");
DataBaseMain data = new DataBaseMain(this);
data.open();
videos = data.getWorkOutVideo(s);
data.close();
if(videos == null || videos.length < 1)
return;
LinearLayout linear = (LinearLayout) findViewById(R.id.dateMain);
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
for(int i = 0; i < videos.length; i++){
VideoView video = new VideoView(this);
video.setVideoPath(videos[i]);
video.setLayoutParams(lp);
video.setId(i+50);
video.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View arg0) {
selectedVideo = arg0.getId();
onButtonClickEvent(arg0);
return true;
}
});
linear.addView(video);
}
}