lundi 22 juin 2015

Increase video cursor count automatic

i have record video by custom camera and store in gallery in particular folder and store video in sqlite database. while fetching video i have got problem cursor value increase automaically.I have close cursor but same issue got. here is my code, i have tried to much to resolve this issue but didn't success.

also i have remove app from phone as well as delete folder clear cache memory but same issue got after these things.

if anybody have idea please help me out this problem

 Globel variables 
 private int video_column_index;
 int count;
 private Cursor videocursor;
 // for database
 ArrayList<HashMap<String, String>> dbArray;

class...

try {
     // fetching data from database
        DataBase con = new DataBase(context);
        dbArray = con.getRecordedVideo();
        con.close();
        Log.e("test", "data by recordedvideo :" + dbArray.size());
        for (int i = 0; i < dbArray.size(); i++) {
            ArrayList<String> al_month = new ArrayList<String>();
            HashMap<String, String> tempHM = dbArray.get(i);
            al_month.add(tempHM.get("video_category"));
            al_month.add(tempHM.get("address"));
            al_month.add(tempHM.get("latitude"));
            al_month.add(tempHM.get("longitude"));
            al_month.add(tempHM.get("title_video"));
            al_month.add(tempHM.get("date_time"));
            al_month.add(tempHM.get("upload_status"));
            al_month.add(tempHM.get("video_duration"));

        }

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

private void init_phone_video_grid() {

    System.gc();
    try {

        File file = null;

        if (Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED)) {
            file = new File(Environment.getExternalStorageDirectory()
                    .getAbsolutePath() + File.separator + "WWLMedia");
            if (file.mkdirs()) {
            }
        } else {
            Log.e("testing", "External Directory is not mounted");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    String dirPath = Environment.getExternalStorageDirectory()
            .getAbsolutePath()
            + File.separator
            + "WWLMedia"
            + File.separator;

    ContentValues values = new ContentValues();
    values.put(MediaStore.Video.Media.DATA, dirPath);
    ContentResolver resolver = getActivity().getContentResolver();
    resolver.insert(Video.Media.EXTERNAL_CONTENT_URI, values);

    String[] proj = { MediaStore.Video.Media._ID,
            MediaStore.Video.Media.DATA,
            MediaStore.Video.Media.DISPLAY_NAME,
            MediaStore.Video.Media.SIZE };

    String selection = MediaStore.Video.Media.DATA + " like?";

    String[] selectionArgs = new String[] { "%WWLMedia%" };

    videocursor = getActivity().getContentResolver().query(
            MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, selection,
            selectionArgs, MediaStore.Video.Media.DATE_TAKEN + " DESC");

    count = videocursor.getCount();
    // count = videocursor.getInt(0);
    Log.e("test", "count :-" + videocursor.getCount());

    if (dbArray.size() > 0) {

        Log.e("test",
                "dbarray  and count > o ::" + count + " , "
                        + dbArray.size());
        lvrecordingvideo.setAdapter(new VideoAdapter(context));


    } else {

    }

}

// this is adapter to show videos

  public class VideoAdapter extends BaseAdapter {
    private Context vContext;

    public VideoAdapter(Context c) {
        vContext = c;
    }

    public int getCount() {
        return count;
    }

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

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

    public View getView(final int position, View convertView,
            ViewGroup parent) {
        System.gc();
        ViewHolder holder;
        String id = null;
        convertView = null;
        if (convertView == null) {
            try {
                convertView = LayoutInflater.from(vContext).inflate(
                        R.layout.custom_newsfeeds, parent, false);
                holder = new ViewHolder();
                holder.txttitlerecording_video_title = (TextView) convertView
                        .findViewById(R.id.txttitlerecording_video_title);
                // holder.txtSize = (TextView) convertView
                // .findViewById(R.id.txtvideosize);
                holder.tvrecording_location = (TextView) convertView
                        .findViewById(R.id.tvrecording_location);
                holder.txtvideorecord_category = (TextView) convertView
                        .findViewById(R.id.txtvideorecord_category);

                holder.ivrecording_thumbnail = (ImageView) convertView
                        .findViewById(R.id.ivrecording_thumbnail);
                holder.ivrecording_category = (ImageView) convertView
                        .findViewById(R.id.ivrecording_category);

                holder.rlrecordingplay_icon = (RelativeLayout) convertView
                        .findViewById(R.id.rlrecordingplay_icon);

                try {

                    video_column_index = videocursor
                            .getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);

                    videocursor.moveToPosition(position);

                    id = videocursor.getString(video_column_index);
                    video_column_index = videocursor
                            .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
                    videocursor.moveToPosition(position);

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

                if (dbArray.size() > 0) {
                    holder.txttitlerecording_video_title.setText(dbArray
                            .get(position).get("title_video"));
                    // holder.txtSize.setText(" Size(KB):"
                    // + videocursor.getString(video_column_index));
                    holder.tvrecording_location.setText(dbArray.get(
                            position).get("address"));

                    if (dbArray.get(position).get("video_category")
                            .equals("Accident")) {
                        holder.ivrecording_category
                                .setBackgroundResource(R.drawable.accident2);
                    } else if (dbArray.get(position).get("video_category")
                            .equals("Fire")) {
                        holder.ivrecording_category
                                .setBackgroundResource(R.drawable.fire2);
                    } else if (dbArray.get(position).get("video_category")
                            .equals("Crime")) {
                        holder.ivrecording_category
                                .setBackgroundResource(R.drawable.crime2);
                    } else if (dbArray.get(position).get("video_category")
                            .equals("Politics")) {
                        holder.ivrecording_category
                                .setBackgroundResource(R.drawable.politics2);
                    } else if (dbArray.get(position).get("video_category")
                            .equals("Weather")) {
                        holder.ivrecording_category
                                .setBackgroundResource(R.drawable.weather2);
                    } else if (dbArray.get(position).get("video_category")
                            .equals("War")) {
                        holder.ivrecording_category
                                .setBackgroundResource(R.drawable.war2);
                    } else if (dbArray.get(position).get("video_category")
                            .equals("Celebrity")) {
                        holder.ivrecording_category
                                .setBackgroundResource(R.drawable.celeb2);
                    } else if (dbArray.get(position).get("video_category")
                            .equals("Sports")) {
                        holder.ivrecording_category
                                .setBackgroundResource(R.drawable.sports2);
                    }
                    holder.txtvideorecord_category.setText(dbArray.get(
                            position).get("video_category"));

                }

                String[] proj = { MediaStore.Video.Media._ID,
                        MediaStore.Video.Media.DISPLAY_NAME,
                        MediaStore.Video.Media.DATA };

                Cursor cursor = getActivity().getContentResolver().query(
                        MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj,
                        MediaStore.Video.Media.DISPLAY_NAME + "=?",
                        new String[] { id }, null);

                cursor.moveToFirst();
                long ids = cursor.getLong(cursor
                        .getColumnIndex(MediaStore.Video.Media._ID));
                cursor.close();

                ContentResolver crThumb = getActivity()
                        .getContentResolver();
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 1;
                Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(
                        crThumb, ids,
                        MediaStore.Video.Thumbnails.MICRO_KIND, options);
                holder.ivrecording_thumbnail.setImageBitmap(curThumb);

                holder.rlrecordingplay_icon
                        .setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View v) {

                                video_column_index = videocursor
                                        .getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
                                videocursor.moveToPosition(position);

                                String filename = videocursor
                                        .getString(video_column_index);

                                Log.e("test", "fadfjsfkdajkl" + filename);

                                Uri data = Uri.parse(filename);
                                Intent intent = new Intent(
                                        android.content.Intent.ACTION_VIEW);
                                intent.setDataAndType(data, "video/mp4");
                                startActivity(intent);
                            }
                        });
                curThumb = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return convertView;
    }
}

static class ViewHolder {

    TextView txttitlerecording_video_title, txtvideorecording_duration,
            tvrecording_location, txtvideorecord_category;
    ImageView ivrecording_thumbnail, ivrecording_category;
    RelativeLayout rlrecordingplay_icon;

}

Aucun commentaire:

Enregistrer un commentaire