我无法从 SD 卡中获取视频并将其设置为 gridview。这就是我目前所困的地方。到目前为止,我的逻辑是我试图将目录设置为字符串数组,然后将这些值与适配器一起使用。我也不太确定将视频转换为缩略图。它当前所做的是显示一个白屏。您的帮助将不胜感激。
public class Gridview extends Activity {
private static final String thepath = "/sdcard/Pictures/";
private static final File path = Environment.getExternalStoragePublicDirectory(thepath);
private static final String TAG = null;
String[] Reelfiles;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preview);
File directory = new File(thepath);
directory.mkdirs();
Reelfiles = directory.list();
GridView gridView = (GridView) findViewById(R.id.gridview);
gridView.setAdapter(new VideoAdapter(this, Reelfiles));
}
public class VideoAdapter extends BaseAdapter {
Context mContext;
Bitmap bmThumbnail;
private String[] Reelfiles;
public VideoAdapter(Context c) {
}
public VideoAdapter(Context context, String[] Reelfiles) {
this.mContext = context;
this.Reelfiles = Reelfiles;
}
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
bmThumbnail = ThumbnailUtils.createVideoThumbnail(Reelfiles[position], Thumbnails.MICRO_KIND);
ImageView imageView = new ImageView(mContext);
imageView.setImageBitmap(bmThumbnail);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
return imageView;
}
}
预览.xml
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
我的日志
04-03 12:18:10.079: E/MediaMetadataRetrieverJNI(14433): getFrameAtTime: videoFrame is a NULL pointer
04-03 12:18:10.089: E/MediaMetadataRetrieverJNI(14433): getFrameAtTime: videoFrame is a NULL pointer
04-03 12:18:10.094: E/MediaMetadataRetrieverJNI(14433): getFrameAtTime: videoFrame is a NULL pointer
04-03 12:18:10.104: V/InputMethodManager(14433): Starting input: tba=android.view.inputmethod.EditorInfo@415218b0 ic=null
04-03 12:18:10.119: E/MediaMetadataRetrieverJNI(14433): getFrameAtTime: videoFrame is a NULL pointer
04-03 12:18:10.264: W/SurfaceView(14433): CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false