3

我正在制作一个应用程序,其中在列表视图中有多个纹理视图。我正在使用我一直使用的列表数组适配器,所以我知道我正在正确地回收每个列表视图项,并且我正在为每个纹理视图中的视频设置正确的 url。但是,如果我的列表包含三个以上的视频,它们就会开始“复制”自己,这意味着第四个列表项会呈现,但视频 1 会在其中呈现,而不是视频 4。此外,当我向下滚动和向后滚动时,有时我已添加到该纹理视图的视频资源也会发生变化,就像它们正在被适配器“重新渲染”一样。我不应该回收视图吗?当前相关代码:

   public class VideoListAdapter extends ArrayAdapter<videoitem>  {

   Context context;

 int phonewidth;
 int videoPlaying =0;

     List<MediaPlayer> playerList = new ArrayList(); 
     int pos;

    private final ImageDownloader mDownload = new ImageDownloader();
    public VideoListAdapter(Context context, int resourceId, List<videoitem> items) {
    super(context, resourceId, items);
     this.context = context;
   phonewidth = context.getResources().getDisplayMetrics().widthPixels;      
 }


   private class ViewHolder {


RelativeLayout wrapper;
InlineVideoPlayer videoPoster;
TextView numberOfLikes;
TextView numberOfDislikes;
ImageView UserIcon;
TextView userName;
TextView created;
ProgressBar p;
LinearLayout l;


   }
  public View getView(final int position, View convertView, ViewGroup parent) {
     ViewHolder holder = null;
 final videoitem rowItem = getItem(position);
     pos = position;

    LayoutInflater mInflater = (LayoutInflater)     context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);



   if (convertView == null) {
        convertView = mInflater.inflate(R.layout.videoitem,parent,  false);
           holder = new ViewHolder();


           holder.wrapper = (RelativeLayout) convertView.findViewById(R.id.videoholder);
           holder.l = (LinearLayout) convertView.findViewById(R.id.inlineVideoPlayer1);
      //       holder.videoPoster.setVideo("http//hub60.com/app/videos/" + rowItem.getVideo());
           holder.UserIcon = (ImageView) convertView.findViewById(R.id.imageView1);
           holder.numberOfDislikes = (TextView) convertView.findViewById(R.id.textView3);
           holder.numberOfLikes = (TextView) convertView.findViewById(R.id.ratinglikes);
           holder.created = (TextView) convertView.findViewById(R.id.textView2);
           holder.userName = (TextView) convertView.findViewById(R.id.textView1);

           holder.numberOfDislikes.setText(Integer.toString(position));
           holder.numberOfLikes.setText(rowItem.getLikes());
           holder.userName.setText(rowItem.getVideo());
           holder.created.setText(rowItem.getCreated());
           mDownload.download(rowItem.getIcon(), holder.UserIcon, null);
           holder.l.getLayoutParams().height = phonewidth;

        //   vid.setLayoutParams(new LayoutParams(
           //     LayoutParams.MATCH_PARENT,
      //          LayoutParams.MATCH_PARENT));


           convertView.setTag(holder);
   } else{
       holder = (ViewHolder) convertView.getTag();

            holder.numberOfDislikes.setText(Integer.toString(position));
            holder.numberOfLikes.setText(rowItem.getLikes());
            holder.userName.setText(rowItem.getVideo());
            holder.created.setText(rowItem.getCreated());
            mDownload.download(rowItem.getIcon(), holder.UserIcon, null);

           convertView.setId(position);


   }



   InlineVideoPlayer vid = new InlineVideoPlayer(rowItem.getVideo(),context);
   ((LinearLayout) holder.l).addView(vid);
   return convertView;
}

在这种特殊情况下,我将它从 if/else 中取出来决定持有人是否为空,并在最后添加有问题的视图。但是,我在 if/else 语句中也有它,并且仍然遇到相同的行为。

自定义纹理视图类

public class InlineVideoPlayer  extends TextureView implements SurfaceTextureListener{
     Context context;
     MediaPlayer mp;
      String url;
     Surface surface;
     SurfaceTexture s;

    public InlineVideoPlayer(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        this.context = context;
    }


    public InlineVideoPlayer(String ur,Context context)
    {
        super(context);
        this.setSurfaceTextureListener(this);
        this.url = ur;
        this.context = context;
    //  startVideo();
        //Log.d("url",this.url);
    }

    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int arg1, int arg2) {

        this.s = surface;

        Log.d("url",this.url);
        startVideo(surface);

    }
    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture arg0) {

        return true;
    }
    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture arg0, int arg1,int arg2) {
    }
    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture arg0) {
    }

    public void setVideo(String url)
    {
        this.url = url;

    }

    public void startVideo(SurfaceTexture t)
    {

            this.surface = new Surface(t);
            this.mp = new MediaPlayer();
            this.mp.setSurface(this.surface);
             try {
                 Uri uri = Uri.parse(this.url);
                 this.mp.setDataSource(this.context, uri);
                 this.mp.prepareAsync();
                 this.mp.setOnPreparedListener(new OnPreparedListener() {
                     public void onPrepared(MediaPlayer mp) {

                        mp.setLooping(true);
                        mp.seekTo(2000);
                        mp.start();
                //      mp.pause();

                    }
                });



                } catch (IllegalArgumentException e1) {
                    e1.printStackTrace();
                } catch (SecurityException e1) {
                    e1.printStackTrace();
                } catch (IllegalStateException e1) {
                    e1.printStackTrace();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }  
               try {

                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (SecurityException e) {
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                }
                try {

                } catch (IllegalStateException e) {
                    e.printStackTrace();
                }




    }

}

先感谢您

4

1 回答 1

0

答案是:这是不可能的,开发人员必须使用可重复使用的单元格,并在合适的单元格的 rightindex 处插入一个电影播放器​​,当创建一个单元格时,当前正在播放的媒体播放器无效

于 2014-01-28T17:30:26.790 回答