Android 仅提供要滑动的位图,不提供url

Android 仅提供要滑动的位图,不提供url,android,android-glide,Android,Android Glide,我有视频网址列表。我根据它们创建缩略图。这些缩略图是以位图的形式出现的。所以我试着 Glide.with(mContext) .load(bitmap) .into(mVideoThumbnail) 我从中发现的。我们可以做类似的事情 Glide.with(mContext) .load(url).asBitmap() .into(mV

我有视频网址列表。我根据它们创建缩略图。这些缩略图是以位图的形式出现的。所以我试着

Glide.with(mContext)
                    .load(bitmap)
                    .into(mVideoThumbnail)
我从中发现的。我们可以做类似的事情

Glide.with(mContext)
                    .load(url).asBitmap()
                    .into(mVideoThumbnail)
但上面的函数用于将URL加载为位图。它不以位图作为参数

我也知道我可以直接将位图设置为下面提到的图像

mVideoThumbnail.setImageBitmap(bitmap);
如果我必须为单个视频设置缩略图,则上述方法效果良好,但在多个视频的情况下,它会导致一些性能问题

我正在共享将缩略图提取为位图并设置到ImageView中的代码。是否有任何方法可以直接将位图传递给Glide,或者有任何其他选项可用于减少性能问题。请帮忙

public class TopicInstructionViewHolder implements View.OnClickListener {
@BindView(R.id.iv_thumbnail)
ImageView mVideoThumbnail;
@BindView(R.id.iv_play_video)
ImageView mVideoPlayIcon;
@BindView(R.id.tv_instruction_name)
TextView mInstructionName;
private ITopicVideoPlayListener mTopicVideoPlayListener;
private Context mContext;
private String videoPath;
private int instructionId;
private boolean mHasVideoSeenBL;

public TopicInstructionViewHolder(View itemView,
                                  ITopicVideoPlayListener mTopicVideoPlayListener,
                                  Context mContext) {
    ButterKnife.bind(this, itemView);
    this.mTopicVideoPlayListener = mTopicVideoPlayListener;
    this.mContext = mContext;
}

public void setData(TopicInstructionDetail topicInstructionDetail) {

    String thumbnailPath = null;
    TopicInstructionTranslationDetail topicInstructionTranslationDetails = findTopicInstructionAsPerLang(topicInstructionDetail.getmTopicInstructionTranslationDetails());
    mVideoPlayIcon.setOnClickListener(this);
    videoPath = topicInstructionTranslationDetails.getmInstructionPath();
    mHasVideoSeenBL = topicInstructionDetail.isCompleteSeen();
    instructionId = topicInstructionTranslationDetails.getmInstructionId();
    mInstructionName.setText(topicInstructionTranslationDetails.getmInstructionName());
    thumbnailPath = (NetworkConstants.VIDEO_URL + topicInstructionTranslationDetails.getmThumbnailPath());

    new SampleAsyncTask().execute(NetworkConstants.VIDEO_URL+videoPath);
    if (topicInstructionDetail.isCompleteSeen()) {
        mVideoPlayIcon.setImageResource(R.drawable.check);
    } else {
        mVideoPlayIcon.setImageResource(R.drawable.ic_play);
    }

}

private TopicInstructionTranslationDetail findTopicInstructionAsPerLang(List<TopicInstructionTranslationDetail> topicInstructionTranslationDetails) {

    TopicInstructionTranslationDetail topicInstructionTranslationDetail = null;
    for (TopicInstructionTranslationDetail topicTranslation : topicInstructionTranslationDetails) {
        if (topicTranslation.getmLanguage().equals(AppPreferencesHelper.getInstance(mContext).getCurrentUserLanguage())) {
            topicInstructionTranslationDetail = topicTranslation;
        }
    }

    if (topicInstructionTranslationDetail == null) {
        topicInstructionTranslationDetail = findDefaultTopicInstruction(topicInstructionTranslationDetails);
    }
    return topicInstructionTranslationDetail;
}

private TopicInstructionTranslationDetail findDefaultTopicInstruction(List<TopicInstructionTranslationDetail> topicInstructionTranslationDetails) {

    TopicInstructionTranslationDetail topicInstructionDetail = null;
    for (TopicInstructionTranslationDetail topicTranslation : topicInstructionTranslationDetails) {
        if (topicTranslation.getmLanguage().equals(LanguageCode.getLanguageCode(LanguageCode.LANGUAGE_FIRST))) {
            topicInstructionDetail = topicTranslation;
        }
    }
    return topicInstructionDetail;
}

@Override
public void onClick(View view) {
    mTopicVideoPlayListener.playVideo(videoPath, instructionId, mHasVideoSeenBL);
}
公共类TopicInstructionViewHolder实现View.OnClickListener{
@BindView(R.id.iv_缩略图)
图像视图缩略图;
@BindView(R.id.iv_播放_视频)
ImageView MVIDEOPLAYCON;
@BindView(R.id.tv\u指令\u名称)
TextView mInstructionName;
私人iTopicVideoPlayiner MTopicVideoPlayiner;
私有上下文;
私有字符串视频路径;
私人int指令ID;
私有布尔mHasVideoSeenBL;
公共主题说明视图持有者(视图项视图,
iTopicVideoPlayliner MTopicVideoPlayliner,
上下文(mContext){
ButterKnife.bind(这个,itemView);
this.mtopicvideoplaylayener=mtopicvideoplaylayener;
this.mContext=mContext;
}
public void setData(TopicInstructionDetail TopicInstructionDetail){
字符串thumbnailPath=null;
TopicInstructionTranslationDetail topicInstructionTranslationDetails=findTopicInstructionAsPerLang(topicInstructionDetail.getmTopicInstructionTranslationDetails());
mvideoplaycon.setOnClickListener(此);
videoPath=topicInstructionTranslationDetails.getmInstructionPath();
mHasVideoSeenBL=主题说明详细信息.isCompleteSeen();
instructionId=topicInstructionTranslationDetails.getmInstructionId();
mInstructionName.setText(topicInstructionTranslationDetails.getmInstructionName());
thumbnailPath=(NetworkConstants.VIDEO_URL+topicInstructionTranslationDetails.getmThumbnailPath());
新建SampleAsyncTask().execute(NetworkConstants.VIDEO\u URL+videoPath);
if(topicInstructionDetail.isCompleteSeen()){
mvideoplaycon.setImageResource(R.drawable.check);
}否则{
mvideoplaycon.setImageResource(R.drawable.ic_play);
}
}
私有TopicInstructionTranslationDetail findTopicInstructionAsPerLang(列出topicInstructionTranslationDetails){
TopiInstructionTranslationDetail TopiInstructionTranslationDetail=null;
对于(Topic指令翻译详细信息Topic翻译:Topic指令翻译详细信息){
if(topicTranslation.getmlLanguage().equals(AppPreferencesHelper.getInstance(mContext.getCurrentUserLanguage())){
TopiInstructionTranslationDetail=TopiTranslation;
}
}
if(topicInstructionTranslationDetail==null){
TopiInstructionTranslationDetail=FindDefaultTopiInstruction(TopiInstructionTranslationDetails);
}
返回主题说明TranslationDetail;
}
私有Topic指令TranslationDetail FindDefaultTopic指令(列出Topic指令TranslationDetails){
TopicInstructionTranslationDetail topicInstructionDetail=null;
对于(Topic指令翻译详细信息Topic翻译:Topic指令翻译详细信息){
if(topicTranslation.getmlLanguage().equals(LanguageCode.getLanguageCode(LanguageCode.LANGUAGE_优先))){
Topic指令细节=Topic翻译;
}
}
返回主题说明详细信息;
}
@凌驾
公共void onClick(视图){
mtopicvideoplayliner.playVideo(视频路径、指令ID、mHasVideoSeenBL);
}
//从视频url获取位图 私有类SampleAsyncTask扩展异步任务{

    @Override
    protected Bitmap doInBackground(String... strings) {
        Bitmap bitmap = null;
        MediaMetadataRetriever mediaMetadataRetriever = null;
        try {
            mediaMetadataRetriever = new MediaMetadataRetriever();
            if (Build.VERSION.SDK_INT >= 14) {
                mediaMetadataRetriever.setDataSource(strings[0], new HashMap<String, String>());
            } else {
                mediaMetadataRetriever.setDataSource(strings[0]);
            }
            bitmap = mediaMetadataRetriever.getFrameAtTime(1, MediaMetadataRetriever.OPTION_CLOSEST);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (mediaMetadataRetriever != null) {
                mediaMetadataRetriever.release();
            }
        }
        return bitmap;
    }

    @Override
    protected void onPostExecute(Bitmap s) {
        super.onPostExecute(s);
        try {
            mVideoThumbnail.setImageBitmap(s);
           /* Glide.with(mContext)
                    .load(s).asBitmap()
                    .into(mVideoThumbnail);*/
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
}
@覆盖
受保护位图doInBackground(字符串…字符串){
位图=空;
MediaMetadataRetriever MediaMetadataRetriever=null;
试一试{
mediaMetadataRetriever=新的mediaMetadataRetriever();
如果(Build.VERSION.SDK_INT>=14){
setDataSource(字符串[0],新HashMap());
}否则{
setDataSource(字符串[0]);
}
位图=mediaMetadataRetriever.getFrameAtTime(1,mediaMetadataRetriever.OPTION_);
}捕获(例外e){
e、 printStackTrace();
}最后{
if(mediaMetadataRetriever!=null){
mediaMetadataRetriever.release();
}
}
返回位图;
}
@凌驾
受保护的void onPostExecute(位图s){
super.onPostExecute(s);
试一试{
mVideoThumbnail.setImageBitmap;
/*使用(mContext)滑动
.load.asBitmap()
.进入(MVA)*/
}
捕获(例外e){
e、 printStackTrace();
}
}
}

}

使用壁画库而不是滑动。

您可以使用facebook库而不是glide,以便在列表中平滑高效地加载。Fresco库提供了在列表中加载图像缩略图的技术。使用Asynctask和fresco管道从视频中获取缩略图并加载


检查此项,为您的问题实施解决方案。

您正在使用Glide v3。Glide v4添加了一个选项,用于将
位图
加载为
可绘制
。文件

更新到v4需要更多配置,请检查