Click here to Skip to main content
15,891,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to Implement MovetoFirst and MovetoNext Functions for my videolist app. Can some help me here. Because of which my app is failing

Videolist.Java

Java
package shashank_balaganchi.sbsvideoplayer;

/**
 * Created by shashank on 04-10-2015.
 */

import android.app.*;
import android.content.Context;
import android.content.Intent;
import android.database.*;
import android.net.Uri;
import android.os.*;
import android.provider.*;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

public class Videolist extends Activity {

    private Cursor videoCursor;
    private int videoColumnIndex;
    ListView videolist;
    int count;
    String thumbPath;
    SwipeRefreshLayout swipeLayout;

    String[] thumbColumns = { MediaStore.Video.Thumbnails.DATA,MediaStore.Video.Thumbnails.DATA,MediaStore.Video.Thumbnails.VIDEO_ID };
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.filelist);

        initialization();
    }

    public void initialization()
    {
        System.gc();
        String[] videoProjection = { MediaStore.Video.Media._ID,MediaStore.Video.Media.DATA,
                MediaStore.Video.Media.DISPLAY_NAME,MediaStore.Video.Media.SIZE };
        videoCursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,videoProjection, null, null, null);
        count = videoCursor.getCount();

        videolist = (ListView) findViewById(R.id.PhoneVideoList);
        videolist.setAdapter(new VideoListAdapter(this.getApplicationContext()));
        videolist.setOnItemClickListener(videogridlistener);
    }
     private AdapterView.OnItemClickListener videogridlistener = new AdapterView.OnItemClickListener()
     {

        public void onItemClick(AdapterView parent, View v, int position,long id)
        {
            System.gc();
            videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
            videoCursor.moveToPosition(position);
            String filename = videoCursor.getString(videoColumnIndex);
            Log.i("FileName: ", filename);
            Intent intent = new Intent(Videolist.this,ViewVideo.class);
                intent.putExtra("videofilename", filename);
                 startActivity(intent);
        }};

    public class VideoListAdapter extends BaseAdapter
    {
        private Context vContext;
        int layoutResourceId;

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

        public int getCount()
        {
            return videoCursor.getCount();
        }

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

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

        public View getView(int position, View convertView, ViewGroup parent)
        {
            System.gc();
            ViewHolder holder;
            String id = null;
            View listItemRow = null;
            if(listItemRow == null)
            listItemRow = LayoutInflater.from(vContext).inflate(R.layout.listview, parent, false);

            
            TextView txtTitle = (TextView)listItemRow.findViewById(R.id.txtTitle);
            TextView txtSize = (TextView)listItemRow.findViewById(R.id.txtSize);
            ImageView thumbImage = (ImageView)listItemRow.findViewById(R.id.imgIcon);

            videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
            videoCursor.moveToPosition(position);
            txtTitle.setText(videoCursor.getString(videoColumnIndex));


            videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
            videoCursor.moveToPosition(position);
            txtSize.setText(" Size(KB):" + videoCursor.getString(videoColumnIndex));

            int videoId = videoCursor.getInt(videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
            Cursor videoThumbnailCursor = managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
                    thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID+ "=" + videoId, null, null);

            if (videoThumbnailCursor.moveToFirst())
            {
                thumbPath = videoThumbnailCursor.getString(videoThumbnailCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
                Log.i("ThumbPath: ",thumbPath);

            }
            thumbImage.setImageURI(Uri.parse(thumbPath));

            return listItemRow;

        }

    }
    static class ViewHolder {

        TextView txtTitle;
        TextView txtSize;
        ImageView thumbImage;
    }
}
Posted
Comments
Richard MacCutchan 13-Oct-15 16:03pm    
"Because of which my app is failing"
Please do not expect people to try and guess what that is supposed to mean. Edit your question and add full details of what is going wrong, where it is going wrong, and any associated exceptions, error messages etc.
phil.o 13-Oct-15 16:05pm    
Not a question. Please see Code Project QA FAQ and What have you tried?.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900