欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

详解android 视频图片混合轮播实现

程序员文章站 2023-12-03 16:15:58
循环添加视频view  图片view for (int i = 0 ;i

循环添加视频view  图片view

for (int i = 0 ;i<beansarraylist.size();i++){
  if (beansarraylist.get(i).gettype()==1){
    videoplayer = new nicevideoplayer(this);
    controller = new txvideoplayercontroller(this);
    videoplayer.setcontroller(controller);
    videoplayer.setup(beansarraylist.get(i).getvideo(),null);
    videoplayer.continuefromlastposition(false);
    videoplayer.setonstart(new nicevideoplayer.onstart() {
      @override
      public void start() {
        bannerview.startloop(false);
      }
    });
    controller.setonrestartpause(new txvideoplayercontroller.onrestartpause() {
      @override
      public void onstart(boolean start) {
        bannerview.startloop(start);
      }

      @override
      public void onrestart() {

      }
    });
    glideloading.setimage(this,beansarraylist.get(i).getstrurl(),controller.imageview());
    viewlist.add(videoplayer);
  }else {
    imageview img = new imageview(this);
    img.setlayoutparams(new viewgroup.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent));
    img.setscaletype(imageview.scaletype.fit_xy);
    img.setadjustviewbounds(true);

    final int finali = i;
    img.setonclicklistener(new view.onclicklistener() {
      @override
      public void onclick(view v) {
        arraylist<string> imgurl = new arraylist<>();
        int position = 0;
        for (int j = 0 ;j<beansarraylist.size();j++){
          if (beansarraylist.get(j).getstrurl().equals(beansarraylist.get(finali).getstrurl())){
            position = j ;
          }
          imgurl.add(beansarraylist.get(j).getstrurl());
        }
        previewphone.previewphone(activityproductdetails.this,imgurl,position,v);
      }
    });


    glideloading.setimage(this,beansarraylist.get(i).getstrurl(),img);
    viewlist.add(img);

  }

}
bannerview.startloop(true);
bannerview.setonpageselected(new bannerview.onpageselected() {
  @override
  public void onnext() {
    if (videoplayer != null){
      if (videoplayer.isplaying()){
        bannerview.startloop(true);
        videoplayer.pause();
      }
    }

  }

  @override
  public void ontouchevent(motionevent ev) {
    switch (ev.getaction()) {
      case motionevent.action_down:
        bannerview.startloop(false);
        break;
      case motionevent.action_move:
        bannerview.startloop(false);
        break;
      case motionevent.action_up:
      case motionevent.action_cancel:
        if (videoplayer.isplaying()){
          bannerview.startloop(false);
        }else {
          bannerview.startloop(true);
        }
        break;
    }
  }
});

xml应用

<com.zym.common.view.banner.bannerview
  android:id="@+id/banner"
  android:layout_width="match_parent"
  android:layout_height="200dp">

</com.zym.common.view.banner.bannerview>

轮播适配器

public class banneradapter extends pageradapter {

  private list<view> viewlist;
  private int size;
  private final int cachecount = 3;

  public banneradapter(list<view> viewlist) {
    this.viewlist = viewlist;
    size = viewlist.size();
  }

  @override
  public void destroyitem(viewgroup container, int position, object object) {
    if (viewlist.size() > cachecount){
      container.removeview(viewlist.get(position%size));
    }
  }

  @override
  public object instantiateitem(viewgroup container, int position) {
    viewgroup parent = (viewgroup) viewlist.get(position%size).getparent();
    if (parent != null) {
      parent.removeview(viewlist.get(position%size));
    }
    container.addview(viewlist.get(position%size));
    return viewlist.get(position%size);
  }

  @override
  public int getcount() {
    return integer.max_value;
  }

  @override
  public boolean isviewfromobject(view view, object object) {
    return view == object;
  }

详解android 视频图片混合轮播实现

详解android 视频图片混合轮播实现

详解android 视频图片混合轮播实现

以上所述是小编给大家介绍的android 视频图片混合轮播实现详解整合,希望对大家有所帮助