这个方法参数官方给出的说法是这样的

/**
* Sets the data source as a content Uri. Call this method before
* the rest of the methods in this class. This method may be time-consuming.
*
* @param context the Context to use when resolving the Uri
* @param uri the Content URI of the data you want to play
* */

在四大组件中获取Context对象是很简单的,但是在Adapter中就无法简单的获取到Context对象,也就是说无法获取es文件夹下raw中的视频路径…..

    @Override    public void onBindViewHolder(final MViewHolder holder, int position) {        String videoPath = videoList.get(position);//        Log.d("video_info", "onBindViewHolder:视频路径检测 "+videoPath);         VideoView v = holder.getVideo();         ImageView image = holder.getImageView();        v.setVideoURI(Uri.parse(videoPath));//设置路径        //设置视频首帧预览        MediaMetadataRetriever media = new MediaMetadataRetriever();        media.setDataSource(c,Uri.parse(videoPath));//设置数据源        Bitmap bitmap = media.getFrameAtTime();        Log.d(TAG, "onBindViewHolder: bitmap:"+bitmap.getByteCount());        image.setImageBitmap(bitmap);    }

之前一直不理解这个Context是要传谁的上下文…我把几个控件的上下文传了进去,一直报错….
后来突然想到…可能是要传这个activity(我这里是Fragment)的上下文
于是就利用构造注入,传了进来。。。

   VideoAdapter videoAdapter = new VideoAdapter(videoList,getContext());

顺利完成第一帧获取…

更多相关文章

  1. Android文件上传
  2. Android中获取系统的时间
  3. android获取手机电量
  4. android 打开本地相册,并将选择的照片显示到当前界面
  5. android 常用方法集合
  6. Android简单自定义标题栏
  7. 【工具类】Android获取平板物理唯一标识码
  8. android8.0 反射Application 启动过程
  9. Pycharm安装PyQt5的详细教程

随机推荐

  1. Android: 自定义Tab样式,一种简单的方式
  2. Android性能调优利器StrictMode
  3. Android中Home键的监听和拦截
  4. Android简明开发教程二十一:访问Internet
  5. Android中的多进程、多线程
  6. DIY新浪微博Android手机客户端(一)(二)(三)完
  7. 转---Android Audio System 之一:AudioTra
  8. Android弹出键盘布局闪动原理和解决
  9. Android(安卓)TextView预渲染研究
  10. Android(安卓)BOOT Time 优化