Android:MediaMetadataRetriever之setDataSource(Context,Uri)
16lz
2022-01-24
这个方法参数官方给出的说法是这样的
/**
* 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());
顺利完成第一帧获取…
更多相关文章
- Android文件上传
- Android中获取系统的时间
- android获取手机电量
- android 打开本地相册,并将选择的照片显示到当前界面
- android 常用方法集合
- Android简单自定义标题栏
- 【工具类】Android获取平板物理唯一标识码
- android8.0 反射Application 启动过程
- Pycharm安装PyQt5的详细教程