My picture video in android not visible

Hiii all,,, why my video picture not visible in android. I'am use the glide for the video pict but not visible. before i'am use picassso but not work. Thanks before all for you help. I've tried various ways to display the video image but still do not show up too. This the sample picture :

enter image description here

This example the code in the 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) {

        }
    });
   }
  }

This code in adapter :

        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 answer

  • answered 2018-04-17 04:11 Akshay Katariya

    This code will help you to generate a thumbnail of your video at any specific time and then you can set it to you 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);