Guest User

Untitled

a guest
Mar 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCMfbfh6f61rI2-PVlxdsxGQ&maxResults=25&key={API_KEY}
  2.  
  3. public class ChannelActivity extends AppCompatActivity {
  4. ListView lvVideo;
  5. ArrayList<VideoDetails> videoDetailsArrayList;
  6. CustomListAdapter customListAdapter;
  7. String searchName;
  8. String TAG="ChannelActivity";
  9. String URL="https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCMfbfh6f61rI2-PVlxdsxGQ&maxResults=25&key={API_KEY}";
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_channel);
  15. lvVideo=(ListView)findViewById(R.id.videoList);
  16. videoDetailsArrayList=new ArrayList<>();
  17. customListAdapter=new CustomListAdapter(ChannelActivity.this,videoDetailsArrayList);
  18. showVideo();
  19.  
  20. }
  21.  
  22. private void showVideo() {
  23. RequestQueue requestQueue= Volley.newRequestQueue(getApplicationContext());
  24. StringRequest stringRequest=new StringRequest(Request.Method.GET, URL, new Response.Listener<String>() {
  25. @Override
  26. public void onResponse(String response) {
  27. try {
  28. JSONObject jsonObject=new JSONObject(response);
  29. JSONArray jsonArray=jsonObject.getJSONArray("items");
  30. for(int i=0;i<jsonArray.length();i++){
  31. JSONObject jsonObject1 = jsonArray.getJSONObject(i);
  32. JSONObject jsonVideoId=jsonObject1.getJSONObject("id");
  33. JSONObject jsonsnippet= jsonObject1.getJSONObject("snippet");
  34. JSONObject jsonObjectdefault = jsonsnippet.getJSONObject("thumbnails").getJSONObject("medium");
  35. VideoDetails videoDetails=new VideoDetails();
  36.  
  37. String videoid=jsonVideoId.getString("videoId");
  38.  
  39. Log.e(TAG," New Video Id" +videoid);
  40. videoDetails.setURL(jsonObjectdefault.getString("url"));
  41. videoDetails.setVideoName(jsonsnippet.getString("title"));
  42. //videoDetails.setVideoDesc(jsonsnippet.getString("description"));
  43. videoDetails.setVideoDate(jsonsnippet.getString("publishedAt"));
  44. videoDetails.setVideoId(videoid);
  45.  
  46. videoDetailsArrayList.add(videoDetails);
  47. }
  48. lvVideo.setAdapter(customListAdapter);
  49. customListAdapter.notifyDataSetChanged();
  50. } catch (JSONException e) {
  51. e.printStackTrace();
  52. }
  53.  
  54. }
  55. }, new Response.ErrorListener() {
  56. @Override
  57. public void onErrorResponse(VolleyError error) {
  58. error.printStackTrace();
  59. }
  60. });
  61. int socketTimeout = 30000;
  62. RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
  63. stringRequest.setRetryPolicy(policy);
  64. requestQueue.add(stringRequest);
  65.  
  66. }
Add Comment
Please, Sign In to add comment