0

I want to display thumbnails of YouTube videos. URL of videos are retrieved from JSON.

List of these URLs is stored in vm.getVideo_url().

I am splitting URL to get id of URL and by passing id I want to get thumbnail.

By clicking on a particular thumbnail I want to redirect to YouTube.

                    public class ImageAdapters extends BaseAdapter
                     {
                         private Context context;
                         private long enqueue;
                         ArrayList<Video_Items> vs_list;
                         ImageAdapters(Context c,ArrayList<Video_Items> vs_list)
                         {
                         context=c;
                         this.vs_list=vs_list;
                         }
                         public int getCount()
                         {
                             return vs_list.size();
                         }
                         public Object getItem(int pos)
                         {
                             return pos;
                         }
                         public long getItemId(int pos)
                         {
                             return pos;
                         }

                        @Override
                        public View getView(int position, View convertView,
                                ViewGroup parent) {
                             final ImageView imageview=new ImageView(context);
                             imageview.setScaleType(ImageView.ScaleType.FIT_XY);
                             imageview.setLayoutParams(new GridView.LayoutParams(150,120));

                             String s=vm.getVideo_url();
                             String[] string=vm.getVideo_url().split("embed/");
                             System.out.println("Tokens : "+s);
                             String url_id="http://i1.ytimg.com/vi/"+s+"/hqdefault.jpg";
                             Picasso.with(getApplicationContext()).load(url_id).into(imageview);

                            imageview.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    // TODO Auto-generated method stub

                                    Intent intent=new Intent(Intent.ACTION_VIEW);  
                                    intent.setData(Uri.parse(vm.getVideo_url()));  
                                    startActivity(intent);  

                                }
                            });
                             return imageview;
                        }

URL is not splitting and thumbnail are not generated.

How to redirect with this?

KVC
  • 46
  • 5
  • post one full url example to see if you require a split or a cut – Tasos Oct 29 '15 at 11:40
  • Here is URL .."video_url": "https://www.youtube.com/embed/PGatzxZx7u8", – KVC Oct 29 '15 at 12:00
  • I want to split it from "embed/" – KVC Oct 29 '15 at 12:01
  • so its best if you remove everything before the last slash -- http://stackoverflow.com/questions/9515505/how-to-get-the-string-after-last-comma-in-java – Tasos Oct 29 '15 at 16:29
  • "List of these URLs is stored in vm.getVideo_url()." This is wrong, according to the comment under my answer. So please share only useful and not misleading information. – dragi Oct 30 '15 at 09:22

1 Answers1

0

You are using the wrong object. Instead use it like this:

String s=vm.getVideo_url();
String[] string=vm.getVideo_url().split("embed/");
System.out.println("Tokens : " + string[0] + " and youtube id = " + string[1]);
String url_id="http://i1.ytimg.com/vi/"+string[1]+"/hqdefault.jpg";

The difference is in using string[1] as the container for the youtube id, instead of s, that simply contains the complete url.

dragi
  • 3,385
  • 5
  • 22
  • 40
  • It retrieves only last URL from the list of URLs from JSON. I want all the URLs from JSON. – KVC Oct 29 '15 at 14:52
  • Then it is easier to help if you post the content of vm.getVideo_url(). – dragi Oct 29 '15 at 15:00
  • I have created a class named **Video_Items** and its object is vm.public String getVideo_url() { return video_url; } public void setVideo_url(String video_url) { this.video_url = video_url; } and setting it using JSON like this for(int i=0; i – KVC Oct 30 '15 at 05:20
  • length of **vm.getVideo_url()** shows last URL only. Can I use **ArrayList vs_list** ? As its size is same as numer of URLs I am having in JSON. – KVC Oct 30 '15 at 05:22
  • `vm` is only one item, but I see you are adding each item to `video_list`. I don't know where you use `vs_list`, so I don't know if it is fine to use it. But `video_list` seems ok to be used for this. You need to iterate over `video_list` and split each item from this list, and then store the result maybe in a String[], where you will have a lot of `url_id`s. In order to help you more, please post the needed source code, by updating your question. – dragi Oct 30 '15 at 09:19