Как известно, встроенный медиа-сканер на Android периодически сканирует всю файловую систему и генерирует миниатюры для просмотра мультимедиа (фото + видео). Это миниатюры, отображаемые приложением Gallery.Получение автоматических видеороликов MediaScanner
В моем приложении у меня есть карусель, где я хочу, чтобы отобразить автоматически генерируемые эскизы для видео только. По соображениям скорости, а так как они уже есть. К сожалению, документы очень скудны, как их получить.
public class MainActivity extends Activity {
private Cursor cursor;
private int columnIndex;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
// Set up an array of the Thumbnail Image ID column we want
String[] projection = {MediaStore.Video.Thumbnails.VIDEO_ID};
// Create the cursor pointing to the SDCard
cursor = managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
null);
System.err.println("qqq video cnt=" + cursor.getCount());
// Get the column index of the Thumbnails Image ID
columnIndex = cursor.getColumnIndexOrThrow(projection[0]);
GridView sdcardImages = (GridView) findViewById(R.id.sdcard);
sdcardImages.setAdapter(new ImageAdapter(this));
// Set up a click listener
sdcardImages.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
// Get the data location of the image
String[] projection = {MediaStore.Video.Media.DATA};
cursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
null);
columnIndex = cursor.getColumnIndexOrThrow(projection[0]);
cursor.moveToPosition(position);
// Get image filename
String imagePath = cursor.getString(columnIndex);
// Use this path to do further processing, i.e. full screen display
System.err.println("qqq path=" + imagePath);
}
});
}
private class ImageAdapter extends BaseAdapter {
private Context context;
public ImageAdapter(Context localContext) {
context = localContext;
}
public int getCount() {
System.err.println("qqq count " + cursor.getCount());
return cursor.getCount();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView picturesView;
if (convertView == null) {
picturesView = new ImageView(context);
// Move cursor to current position
cursor.moveToPosition(position);
// Get the current value for the requested column
int imageID = cursor.getInt(columnIndex);
Uri uri = Uri.withAppendedPath(
MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID);
System.err.println("qqq getview uri="+uri.toString());
// Set the content of the image based on the provided URI
picturesView.setImageURI(uri);
picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
picturesView.setPadding(8, 8, 8, 8);
picturesView.setLayoutParams(new GridView.LayoutParams(100, 100));
//picturesView.setImageBitmap(BitmapFactory.decodeResource(getResources(), android.R.drawable.ic_btn_speak_now));
}
else {
picturesView = (ImageView)convertView;
}
return picturesView;
}
}
}
Журнал, который я получаю, выглядит следующим образом. Он показывает правильное количество видео (2), но даже при том, что URL-адрес миниатюры «выглядит нормально», возвращаемый объект Bitmap равен нулю. Есть идеи?
W/System.err: qqq video cnt=2
W/System.err: qqq count 2
W/System.err: qqq count 2
W/System.err: qqq count 2
W/System.err: qqq getview uri=content://media/external/video/thumbnails/2484
W/System.err: qqq getview uri=content://media/external/video/thumbnails/2483
W/System.err: qqq count 2
W/System.err: qqq getview uri=content://media/external/video/thumbnails/2484
W/System.err: qqq count 2