视频库与Parse后端

时间:2016-03-27 14:38:59

标签: android video parse-platform android-gridview

我创建了一个FeedsAdapter,我想加载Parse后端存储的视频的所有缩略图。

FeedsFragment

 GridView gridview;
    List<ParseObject> ob;
    FeedsGridAdapter adapter;
    private List<ParseFeeds> phonearraylist = null;
    View rootView;

    public static final String TAG = FeedsFragment.class.getSimpleName();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.feeds_layout,
                container, false);
        new RemoteDataTask().execute();
        return rootView;
    }


    private class RemoteDataTask extends AsyncTask<Void,Void,Void> {

       @Override
       protected void onPreExecute() {
           super.onPreExecute();
       }

        @Override
        protected Void doInBackground(Void... params) {
            // Create the array
            phonearraylist = new ArrayList<ParseFeeds>();
            try {
                // Locate the class table named "SamsungPhones" in Parse.com
                ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                        "AroundMe");
                // Locate the column named "position" in Parse.com and order list
                // by ascending
                //query.whereEqualTo(ParseConstants.KEY_RECIPIENT_IDS, ParseUser.getCurrentUser().getUsername());
                query.orderByAscending("createdAt");
                ob = query.find();
                for (ParseObject country : ob) {
                    ParseFile image = (ParseFile) country.get("videoThumbs");
                   ParseFeeds map = new ParseFeeds();
                    map.setPhone(image.getUrl());
                    phonearraylist.add(map);
                }
            } catch (ParseException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            // Locate the gridview in gridview_main.xml
            gridview = (GridView) rootView.findViewById(R.id.gridview);
            // Pass the results into ListViewAdapter.java
            adapter = new FeedsGridAdapter(FeedsFragment.this.getActivity(),
                    phonearraylist);
            // Binds the Adapter to the ListView
            gridview.setAdapter(adapter);
        }
    }

这是我为加载缩略图而创建的适配器,我也想将意图视频网址传递给SingleVideoActivity。

Context context;
    LayoutInflater inflater;
    ImageLoader imageLoader;
    private List<ParseFeeds> phonearraylist = null;
    private ArrayList<ParseFeeds> arraylist;

    public FeedsGridAdapter(Context context, List<ParseFeeds> phonearraylist) {
        this.context = context;
        this.phonearraylist = phonearraylist;
        inflater = LayoutInflater.from(context);
        this.arraylist = new ArrayList<ParseFeeds>();
        this.arraylist.addAll(phonearraylist);
        imageLoader = new ImageLoader(context);
    }

    public class ViewHolder {
        ImageView phone;
    }

    @Override
    public int getCount() {
        return phonearraylist.size();
    }

    @Override
    public Object getItem(int position) {
        return phonearraylist.get(position);
    }

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

    public View getView(final int position, View view, ViewGroup parent) {
        final ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.feeds_layout, null);
            // Locate the ImageView in gridview_item.xml
            holder.phone = (ImageView) view.findViewById(R.id.videoThumb);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        // Load image into GridView
        Picasso.with(context)
                .load(phonearraylist.get(position).getPhone())
                .error(R.drawable.error_placeholder_image)
                .into(holder.phone, new com.squareup.picasso.Callback() {
                    @Override
                    public void onSuccess() {
                        Log.d(TAG, "onSuccess");
                    }

                    @Override
                    public void onError() {
                        Log.d(TAG, "Error ocurred");
                    }
                });
        // Capture GridView item click
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // Send single item click data to SingleItemView Class
                Intent intent = new Intent(context, SingleVideoView.class);
                // Pass all data phone
                intent.putExtra("phone", phonearraylist.get(position)
                        .getPhone());
                context.startActivity(intent);
            }
        });
        return view;
    }

这是Parse Class

Parse Class

它总是在Picasso.loadwith(context)上给我null。但是,当我在Parse类中加载没有视频的唯一图像时,只需查询图像就可以正常工作,但是当我在类中查询视频时,它会给我null。我不明白我的查询是错误的,或者实现这种流程的正确方法是什么。

0 个答案:

没有答案