我目前有一种方法可以从设备中获取所有视频并显示在listview
中。目前,我只显示相册名称和标题,其缩略图的默认图像在listview
的所有行中重复显示。这样做的方法是
try {
mAdapter = new SimpleCursorAdapter(
this,
// Use a template that displays a text view
R.layout.media_select_row,
null,
// Map from database columns...
new String[] {
MediaStore.Video.Media.ALBUM,
MediaStore.Video.Media.TITLE,
MediaStore.Video.Media._ID},
// To widget ids in the row layout...
new int[] {
R.id.row_album,
R.id.row_title,
R.id.row_icon,},
0);
setListAdapter(mAdapter);
getListView().setItemsCanFocus(true);
// Normal click - open the editor
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view,
int position,
long id) {
Cursor c = mAdapter.getCursor();
int dataIndex = c.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
String filename = c.getString(dataIndex);
videoFilename = filename;
String substr = videoFilename.substring(videoFilename.length() - 3);
if(substr.equals("mp4")) {
if(callPath == 1) {
Intent intent = new Intent(DubVideoList.this, DubStudio.class);
intent.putExtra("videoPath", videoFilename);
startActivity(intent);
}else if(callPath == 2){
Intent intent = new Intent(DubVideoList.this, DubStudioBeta.class);
intent.putExtra("videoPath", videoFilename);
startActivity(intent);
}
}else{
Toast.makeText(DubVideoList.this,getString(R.string.mp4_support),Toast.LENGTH_LONG).show();
}
}
});
mInternalCursor = null;
mExternalCursor = null;
getLoaderManager().initLoader(INTERNAL_CURSOR_ID, null, this);
getLoaderManager().initLoader(EXTERNAL_CURSOR_ID, null, this);
} catch (SecurityException e) {
// No permission to retrieve video?
Log.e("SecurityError", e.toString());
// TODO error 1
} catch (IllegalArgumentException e) {
// No permission to retrieve video?
Log.e("IllegalArgument", e.toString());
// TODO error 2
}
mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.row_icon) {
setSoundIconFromCursor((ImageView) view, cursor);
return true;
}
return false;
}
});
现在我需要用视频缩略图替换每个单元格的默认图像?有没有办法做到这一点 ?我也给了行XML
作为参考。提前谢谢。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:id="@+id/row_icon"
android:gravity="center_vertical"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:src="@drawable/filmicon"
android:layout_gravity="center" />
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_marginTop="8dip"
android:layout_marginBottom="8dip"
android:layout_width="0px"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_marginRight="4dip">
<TextView android:id="@+id/row_title"
android:textColor="#ff000000"
android:textSize="18sp"
android:singleLine="true"
android:shadowColor="#999999"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/row_album"
android:textColor="#ff1bbcff"
android:textSize="12sp"
android:singleLine="true"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
要获取缩略图,您可以使用此代码
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(video_path,
MediaStore.Images.Thumbnails.MINI_KIND);
答案 1 :(得分:0)
使用此代码在列表视图中添加视频缩略图。
方法:1
位图bMap = ThumbnailUtils.createVideoThumbnail(“本地文件路径”, MediaStore.Video.Thumbnails.MINI_KIND); MViewHolder.imageThumb.setImageBitmap(bMap);
方法:2
使用滑行
编译'com.github.bumptech.glide:glide:3.7.0'
滑翔
.with(上下文)
.load(Uri.fromFile(new File(filePath)))
.into(MViewHolder.imageThumb);