Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCMfbfh6f61rI2-PVlxdsxGQ&maxResults=25&key={API_KEY}
- public class ChannelActivity extends AppCompatActivity {
- ListView lvVideo;
- ArrayList<VideoDetails> videoDetailsArrayList;
- CustomListAdapter customListAdapter;
- String searchName;
- String TAG="ChannelActivity";
- String URL="https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCMfbfh6f61rI2-PVlxdsxGQ&maxResults=25&key={API_KEY}";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_channel);
- lvVideo=(ListView)findViewById(R.id.videoList);
- videoDetailsArrayList=new ArrayList<>();
- customListAdapter=new CustomListAdapter(ChannelActivity.this,videoDetailsArrayList);
- showVideo();
- }
- private void showVideo() {
- RequestQueue requestQueue= Volley.newRequestQueue(getApplicationContext());
- StringRequest stringRequest=new StringRequest(Request.Method.GET, URL, new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- try {
- JSONObject jsonObject=new JSONObject(response);
- JSONArray jsonArray=jsonObject.getJSONArray("items");
- for(int i=0;i<jsonArray.length();i++){
- JSONObject jsonObject1 = jsonArray.getJSONObject(i);
- JSONObject jsonVideoId=jsonObject1.getJSONObject("id");
- JSONObject jsonsnippet= jsonObject1.getJSONObject("snippet");
- JSONObject jsonObjectdefault = jsonsnippet.getJSONObject("thumbnails").getJSONObject("medium");
- VideoDetails videoDetails=new VideoDetails();
- String videoid=jsonVideoId.getString("videoId");
- Log.e(TAG," New Video Id" +videoid);
- videoDetails.setURL(jsonObjectdefault.getString("url"));
- videoDetails.setVideoName(jsonsnippet.getString("title"));
- //videoDetails.setVideoDesc(jsonsnippet.getString("description"));
- videoDetails.setVideoDate(jsonsnippet.getString("publishedAt"));
- videoDetails.setVideoId(videoid);
- videoDetailsArrayList.add(videoDetails);
- }
- lvVideo.setAdapter(customListAdapter);
- customListAdapter.notifyDataSetChanged();
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- error.printStackTrace();
- }
- });
- int socketTimeout = 30000;
- RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
- stringRequest.setRetryPolicy(policy);
- requestQueue.add(stringRequest);
- }
Add Comment
Please, Sign In to add comment