Android中的图片视频不可见

时间:2018-04-17 04:11:11

标签: android android-glide

为什么我的视频图片在Android中不可见?我将幻灯片用于视频图片,但不可见。在我使用毕加索之前,但没有工作。我尝试了各种方式来显示视频图像,但仍然没有显示出来。 这样的样本图片:

enter image description here

此示例是VideoActivity中的代码:

public class CCVideoActivity extends AppCompatActivity {

@BindView(R.id.video)
VideoView video;
@BindView(R.id.txtjudul)
TextView txtjudul;
@BindView(R.id.rvccvideo2)
RecyclerView rvccvideo2;

Tutorial tutorial;

@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_ccvideo);
    ButterKnife.bind(this);

    //init actionbar
    Util.setCustomActionBar(this)
            .setTitle("Tips")
            .setLeftButton(R.drawable.button_back, new 
  View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            })
            .setRightButton(null, null);

    tutorial = getIntent().getParcelableExtra("tutorial");
    String titles = tutorial.title;
    String videos = tutorial.video;


    txtjudul.setText(titles);
    video.setVideoPath(videos);
    video.setMediaController(new MediaController(this));
    video.requestFocus();
    video.start();

    //untuk menunggu server response, supaya user tdk bingung saat proses 
    berjalan
    final ProgressDialog dialog = new ProgressDialog(CCVideoActivity.this);
    //set message dialog
    dialog.setMessage("loading");
    //supaya gabisa di cancel
    dialog.setCancelable(false);
    //tampilkan
    dialog.show();

    //get konfigurasi dari retrofit
    ApiServices api = InitRetrofit.getInstanceRetrofit();

    Call<APIResponse<CoachingClinic>> call = api.get_cctutorial();

    call.enqueue(new Callback<APIResponse<CoachingClinic>>() {
        @Override
        public void onResponse(Call<APIResponse<CoachingClinic>> call, 
    Response<APIResponse<CoachingClinic>> response) {
            if (response.isSuccessful()) {
                dialog.dismiss();
                ArrayList<Tutorial> data = response.body().data.tutorial;
                CCAdapter ar = new CCAdapter(CCVideoActivity.this, 
     rvccvideo2, data);
                rvccvideo2.setAdapter(ar);
                rvccvideo2.setLayoutManager(new 
     LinearLayoutManager(CCVideoActivity.this));
            }

        }

        @Override
        public void onFailure(Call<APIResponse<CoachingClinic>> call, 
        Throwable t) {

        }
    });
   }
  }

适配器中的此代码:

        public class CCAdapter extends 
  RecyclerView.Adapter<CCAdapter.MyHolder> {

Activity c;
RecyclerView r;
ArrayList<Tutorial> data;

public CCAdapter(Activity c, RecyclerView r, ArrayList<Tutorial> data) {
    this.c = c;
    this.r = r;
    this.data = data;
}

@Override
public CCAdapter.MyHolder onCreateViewHolder(ViewGroup parent, int viewType) 
 {
    LayoutInflater inflater = (LayoutInflater) 
  c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.custom_cc_video, parent, false);
    final MyHolder holder = new MyHolder(v);
    holder.clickArea.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(c, CCVideoActivity.class);
            intent.putExtra("tutorial", 
  data.get(holder.getAdapterPosition()));
            c.startActivity(intent);
        }
    });
    return holder;
 }

@Override
public void onBindViewHolder(CCAdapter.MyHolder holder, int position) {
    holder.cctitle.setText(data.get(position).title);

    String ytID = YoutubeHelper.getYTId(data.get(position).source_url);
    String imgThumbnail = YoutubeHelper.getHQThumbnail(ytID);


    RequestOptions opt = new 
    RequestOptions().placeholder(R.drawable.no_photo);
    Glide.with(c)
            .load(imgThumbnail)
            .apply(opt)
            .into(holder.ccvid);
}

@Override
public int getItemCount() {
    return data.size();
}

public class MyHolder extends RecyclerView.ViewHolder {
    ImageView ccvid;
    TextView cctitle;
    View clickArea;

    public MyHolder(View itemView) {
        super(itemView);
        ccvid = (ImageView) itemView.findViewById(R.id.imgthumbnail);
        cctitle = (TextView) itemView.findViewById(R.id.txttitle);
        clickArea = itemView.findViewById(R.id.ll_click_area);
    }
  }
}

1 个答案:

答案 0 :(得分:0)

此代码可帮助您在任何特定时间生成视频缩略图,然后您可以将其设置为ImageView

BitmapPool bitmapPool = Glide.get(getApplicationContext()).getBitmapPool();
int microSecond = 6000000;// 6th second as an example
VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(microSecond);
FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888);
Glide.with(getApplicationContext())
    .load(yourUri)
    .asBitmap()
    .override(50,50)// Example
    .videoDecoder(fileDescriptorBitmapDecoder)
    .into(yourImageView);