views:

58

answers:

1

After having solved every of my previous issues to get the code running for retrieving videos from the sdcard and displaying them in the GridView, I still cannot see the videos. I don't know what I have done wrong that they won't show and the array isn't passed on.

If someone could help me out, please, because I really haven't got a clue what's wrong... :(( Thank you...

This is the java file that tries to retrieve and display the videos from the sdcard in the GridView:

package com.mobilevideoeditor.moved;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.VideoView;




public class EditGalleryView extends Activity {
    Uri[] vidUris;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videogrid);

        GridView vGrid=(GridView) findViewById(R.id.vgrid);
        vGrid.setAdapter(new VideoAdapter(this));

        Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;

        Log.d("EditGalleryView", "uri:"+uri);
        String[] projection = {
                MediaStore.Video.Media.DESCRIPTION,
                MediaStore.Video.Media.DATA  
    };

        Cursor c = this.managedQuery(uri, projection, null, null,
                MediaStore.Video.Media.DATE_ADDED);
                         Log.d("EditGalleryView", "vids available:" +c.getCount());

                         ArrayList<Uri> experimentVids = new ArrayList<Uri>();


                             if (c.getCount() != 0) {
                                 c.moveToFirst();
                                 experimentVids.add(Uri.parse(c.getString(1)));
                                 while (c.moveToNext()) {
                                         experimentVids.add(Uri.parse(c.getString(1)));

                                  }
                      }
                             Log.d("ClassName", "experimentVids.length:" +experimentVids.size());
                                                  if (experimentVids.size() != 0) {
                                                    vidUris = new Uri[experimentVids.size()];
                                                      for (int i = 0; i < experimentVids.size(); i++) {
                                                          vidUris[i] = experimentVids.get(i);
                                                      }
                                                      Log.d("EditGalleryView", "vidUris:"+vidUris.length);
                                                  }
                                              }


    public class VideoAdapter extends BaseAdapter {
        private Context mContext;

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

        public int getCount() {
            //return mThumbIds.length;
           if(vidUris!=null){
            return vidUris.length;}
        return 0;
        }


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

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

        // create a new ImageView for each item referenced by the Adapter
        public View getView(int position, View convertView, ViewGroup parent) {
           VideoView videoView;
            if (convertView == null) {  // if it's not recycled, initialize some attributes
                videoView = new VideoView(mContext);
                videoView.setVideoURI(vidUris[position]);
                videoView.setLayoutParams(new GridView.LayoutParams(85, 85));
               //videoView.setScaleType(VideoView.ScaleType.CENTER_CROP);
                videoView.setPadding(8, 8, 8, 8);
            } else {
                videoView = (VideoView) convertView;
            }

          //  imageView.setImageResource(mThumbIds[position]);
            return videoView;
        }

       /* // references to our images
        private Integer[] mThumbIds = {
                R.drawable.sample_2, R.drawable.sample_3,
                R.drawable.sample_4, R.drawable.sample_2,
                R.drawable.sample_6, R.drawable.sample_3,
                R.drawable.sample_4, R.drawable.sample_1,

        };*/

    }   

}

Force close Error - ISSUE SOLVED


App Disappearance - ISSUE SOLVED


Array Issue - ISSUE SOLVED

+1  A: 

Make vidUris a member of the EditGalleryView class. Also I think there is a toArray method on ArrayList that will return an array of elements.

Pentium10
Thanks for the help...I solved this problem, but now my app disappeared entirely :(
kivy