下面的代码无法获取位于R.raw
文件夹中的视频的视频缩略图。
我想使用画廊来显示视频的缩略图。视频被放入R.raw
文件夹(实际上我是Android新手,所以我真的不知道将这些视频放在哪里,所以我把它们放在R.raw
文件夹中)。现在我想获取视频的缩略图。但是有人说缩略图只能从 SD 卡中获取。这是真的吗?接下来我应该怎么做?谢谢。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Gallery gallery = (Gallery) findViewById(R.id.gallery);
final String[] videoFileList = new String[] { "R.raw.01", "R.raw.02" };
BaseAdapter adapter = new BaseAdapter() {
public int getCount() {
return videoFileList.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(Select.this);
Bitmap bmThumbnail;
bmThumbnail = ThumbnailUtils.createVideoThumbnail("android.resource://" + getPackageName() + "/"
+ videoFileList[position], Thumbnails.MINI_KIND);
System.out.println(videoFileList[position]);
imageView.setImageBitmap(bmThumbnail);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
TypedArray typedArray = obtainStyledAttributes(R.styleable.Gallery);
imageView.setBackgroundResource(typedArray.getResourceId(
R.styleable.Gallery_android_galleryItemBackground, 0));
return imageView;
}
};
gallery.setAdapter(adapter);
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(Select.this, Play.class);
intent.putExtra("image", videoFileList[position]);
startActivity(intent);
Select.this.finish();
}
public void onNothingClick(AdapterView<?> parent) {
}
});
}