我无法从SD卡播放视频文件。 - 我正在播放SD卡的特定视频文件。 - 从列表中选择视频,它不会播放视频。 - 我将意图传递给videoView类并不是在阅读。
public class AndroidThumbnailList extends ListActivity{
String[] videoFileList = {
"/sdcard/Periodontal/Perio-Probling.mp4",
"/sdcard/Periodontal/Inlays.mp4"
/* "/sdcard/Video/Onlays.mp4",
"/sdcard/Video/Root Canal Treatment.mp4",
"/sdcard/Video/crown4.mp4",
"/sdcard/Video/crown5.mp4",
"/sdcard/Video/crown6.mp4",
"/sdcard/Video/crown7.mp4"*/
};
public class MyThumbnaildapter extends ArrayAdapter<String>{
public MyThumbnaildapter(Context context, int textViewResourceId,
String[] objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
if(row==null){
LayoutInflater inflater=getLayoutInflater();
row=inflater.inflate(R.layout.row, parent, false);
}
row.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if(position==0)
{
Intent intent = new Intent(AndroidThumbnailList.this, ViewVideo.class);
intent.putExtra("videofilename", videoFileList);
startActivity(intent);
}
/*if(position==1)
{
Intent intent = new Intent(mContext, PeriodontalCare.class);
mContext.startActivity(intent);
}
if(position==2)
{
Intent i = new Intent(mContext, CosmeticCare.class);
mContext.startActivity(i);
}*/
}
});
TextView textfilePath = (TextView)row.findViewById(R.id.FilePath);
textfilePath.setText(videoFileList[position]);
ImageView imageThumbnail = (ImageView)row.findViewById(R.id.Thumbnail);
Bitmap bmThumbnail;
bmThumbnail = ThumbnailUtils.createVideoThumbnail(videoFileList[position], Thumbnails.MICRO_KIND);
imageThumbnail.setImageBitmap(bmThumbnail);
return row;
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new MyThumbnaildapter(AndroidThumbnailList.this, R.layout.row, videoFileList));
}
}
我的VideoView类:
public class ViewVideo extends Activity {
private String videoFileList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.videofile);
// mVideoView = (VideoView) findViewById(R.id.surface_view);
System.gc();
Intent i = getIntent();
Bundle extras = i.getExtras();
videoFileList = extras.getString("videofilename");
VideoView vv = new VideoView(getApplicationContext());
setContentView(vv);
vv.setVideoPath(videoFileList);
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.start();
}
}
答案 0 :(得分:1)
您不应该创建新的VideoView
,而是使用VideoView
获取findViewById
:
setContentView(R.layout.videofile);
VideoView vv = (VideoView) findViewById(R.id.surface_view);
// rest of the calls on vv
您不应使用视频文件的硬编码路径,因为它可能会在不同设备之间发生变化。相反,使用类似的东西。
Environment.getExternalStorageDirectory().getAbsolutePath() + "/Periodontal/Perio-Probling.mp4"