在videoview上的android进度条

时间:2014-02-05 11:21:08

标签: java android android-gridview android-progressbar android-videoview

我有一个gridview,其中每个视图都是一个显示rtsp strems的视频。

我想要一个循环进度条,直到视频开始运行。

我有一个问题,视频开始但不会消失,黑屏。这只使用相对布局,如果我使用线性布局,进度条逻辑工作正常,但这不是我想要的。

这是我的gridview适配器代码

public class VideoAdapter extends BaseAdapter {
    private static final String TAG = VideoAdapter.class.getName();
    private Context mContext;
    private GridView mGv;   
    private int ROW_NUMBER = 3;
    private int COL_NUMBER = 3;
     private String[] mvideoSrc;


    public VideoAdapter(Context c, GridView gv,int col,int row,String[] videosrc) {
        mContext = c;
        mGv=gv;
        ROW_NUMBER=row;
        COL_NUMBER=col;
        mvideoSrc=videosrc;

    }

    public int getCount() {
        return ROW_NUMBER*COL_NUMBER;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new VideoView for each item referenced by the Adapter
    @SuppressLint("NewApi")
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View gridView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes


            gridView = new View(mContext);
            gridView = inflater.inflate(it.nexera.visiamobile.R.layout.videoview_layout, null);
            final ProgressBar progressBar = (ProgressBar) gridView.findViewById(it.nexera.visiamobile.R.id.grid_progress);
            VideoView videoView = (VideoView) gridView.findViewById(it.nexera.visiamobile.R.id.grid_videoview);


            WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
            Display display = wm.getDefaultDisplay();
            int width=0;
            int height=0;

            if (android.os.Build.VERSION.SDK_INT >= 13){
                Point size = new Point();
                display.getSize(size);
                width = size.x;
                height = size.y;
            }
            else{
                width = display.getWidth();
                height = display.getHeight();

            }
            // Calculate ActionBar height
            TypedValue tv = new TypedValue();
            int actionBarHeight=0;
            if (mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
            {
                actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,mContext.getResources().getDisplayMetrics());
            }


            TextView textview = (TextView) ((Activity) mContext).findViewById (it.nexera.visiamobile.R.id.txt_grid); 

            int textview_height=textview.getHeight();
            height=height-actionBarHeight-textview_height;
            RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
                    (width/COL_NUMBER),
                    (height/ROW_NUMBER));
//          LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
//                  (width/COL_NUMBER),
//                    (height/ROW_NUMBER));

            videoView.setLayoutParams(param);
            videoView.setFocusable(false);
            videoView.setFocusableInTouchMode(false);

           Uri video = Uri.parse(mvideoSrc[position]);

            videoView.setVideoURI(video);
            progressBar.setVisibility(View.VISIBLE);

            videoView.setOnPreparedListener(new OnPreparedListener() {

                @Override
                public void onPrepared(MediaPlayer mp) {

                    //ProgressBar progressBar = (ProgressBar) gridView.findViewById(it.nexera.visiamobile.R.id.grid_progress);
                    progressBar.setVisibility(View.GONE);
                    mp.start();

                }
            });
          //  videoView.start();

        } else {
            gridView = (View) convertView;
        }
        return gridView;
    }

//

}

这是我对gridview的每个项目的布局,你可以忽略线性布局的注释行

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/GridItem"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:gravity="center_horizontal"
  >

     <ProgressBar
         android:id="@+id/grid_progress"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         style="@android:style/Widget.ProgressBar.Large"
         android:layout_marginRight="5dp"
         android:visibility="gone"
         android:layout_centerInParent="true"
    android:layout_gravity="center"
          />
      <VideoView 
        android:id="@+id/grid_videoview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    </VideoView>



</RelativeLayout>

 <!--
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/GridItem"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:gravity="center_horizontal"
  >

     <ProgressBar
         android:id="@+id/grid_progress"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         style="@android:style/Widget.ProgressBar.Large"
         android:layout_marginRight="5dp"
         android:visibility="gone"
    android:layout_gravity="center"
          />
      <VideoView 
        android:id="@+id/grid_videoview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">


    </VideoView>



</LinearLayout>

 -->

0 个答案:

没有答案