public void savePlaylist() {
   List<YouTubeVideo> videos = ((YouTubeVideoListAdapter) playlist.getAdapter()).getVideos();
   JSONArray videoArr = new JSONArray();
   for (YouTubeVideo video : videos) {
     videoArr.put(video.convertToJSON());
   }
   playlistDetails.update(videoArr.toString());
 }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == SEARCH_YOUTUBE_REQUEST) {
      // Make sure the request was successful
      if (resultCode == Activity.RESULT_OK) {
        String videoId = data.getStringExtra(VIDEO_ID);
        String videoName = data.getStringExtra(VIDEO_NAME);
        String videoImgUrl = data.getStringExtra(VIDEO_IMG_URL);
        long videoDate = data.getLongExtra(VIDEO_DATE, 0);
        String channelName = data.getStringExtra(VIDEO_CHANNEL);

        YouTubeVideo video = new YouTubeVideo();
        video.id = videoId;
        video.name = videoName;
        video.imageUrl = videoImgUrl;
        video.publishedDate = new Date(videoDate);
        video.channelTitle = channelName;

        //                updateWidgetProperty(VIDEO_ID, videoId);

        ((YouTubeVideoListAdapter) playlist.getAdapter()).addVideo(video);
        savePlaylist();

        videoSearchInput.setText("");
      }
    }
  }
  public List<YouTubeVideo> getPlaylist() {
    ArrayList<YouTubeVideo> videos = new ArrayList<>();
    try {
      JSONArray jsonarray = new JSONArray(playlistDetails.value);

      for (int i = 0; i < jsonarray.length(); i++) {
        JSONObject jsonobject = jsonarray.getJSONObject(i);
        videos.add(YouTubeVideo.createFromJson(jsonobject));
      }
    } catch (JSONException e) {
      Log.e(MainActivity.TAG, e.toString());
    }
    return videos;
  }