com.google.api.services.youtube.model.PlaylistListResponse Java Examples

The following examples show how to use com.google.api.services.youtube.model.PlaylistListResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetPlaylistTask.java    From SkyTube with GNU General Public License v3.0 6 votes vote down vote up
private YouTubePlaylist getFirstPlaylist(YouTube.Playlists.List api) {
    List<Playlist> playlistList = null;
    try {
        // communicate with YouTube
        PlaylistListResponse listResponse = api.execute();

        // get playlists
        playlistList = listResponse.getItems();

        if (!playlistList.isEmpty()) {
            Playlist playlist = playlistList.get(0);
            YouTubeChannel channel = channelInfo.getChannelInfoSync(playlist.getSnippet().getChannelId());
            return new YouTubePlaylist(playlist, channel);
        }
        // set the next page token

    } catch (IOException ex) {
        Logger.d(this, ex.getLocalizedMessage());
    }

    return null;
}
 
Example #2
Source File: YouTubeAPI.java    From UTubeTV with The Unlicense 6 votes vote down vote up
private String nextToken() {
  String result = null;

  if (response == null)
    result = ""; // first time
  else {
    // is there a better way of doing this?
    if (response instanceof SearchListResponse) {
      result = ((SearchListResponse) response).getNextPageToken();
    } else if (response instanceof PlaylistItemListResponse) {
      result = ((PlaylistItemListResponse) response).getNextPageToken();
    } else if (response instanceof SubscriptionListResponse) {
      result = ((SubscriptionListResponse) response).getNextPageToken();
    } else if (response instanceof VideoListResponse) {
      result = ((VideoListResponse) response).getNextPageToken();
    } else if (response instanceof PlaylistListResponse) {
      result = ((PlaylistListResponse) response).getNextPageToken();
    } else {
      doHandleExceptionMessage("nextToken bug!");
    }
  }

  return result;
}
 
Example #3
Source File: GetPlaylistTitlesAsyncTask.java    From YouTubePlaylist with Apache License 2.0 6 votes vote down vote up
@Override
protected PlaylistListResponse doInBackground(String[]... params) {

    final String[] playlistIds = params[0];

    PlaylistListResponse playlistListResponse;
    try {
        playlistListResponse = mYouTubeDataApi.playlists()
            .list(YOUTUBE_PLAYLIST_PART)
            .setId(TextUtils.join(",", playlistIds))
            .setFields(YOUTUBE_PLAYLIST_FIELDS)
            .setKey(ApiKey.YOUTUBE_API_KEY)
            .execute();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
     
    return playlistListResponse;
}
 
Example #4
Source File: GetChannelPlaylists.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
public List<YouTubePlaylist> getNextPlaylists() {
	List<Playlist> playlistList = null;

	if (!noMorePlaylistPages()) {
		try {
			// set the page token/id to retrieve
			this.playlistList.setPageToken(nextPageToken);

			// communicate with YouTube
			PlaylistListResponse listResponse = this.playlistList.execute();

			// get playlists
			playlistList = listResponse.getItems();

			// set the next page token
			nextPageToken = listResponse.getNextPageToken();

			// if nextPageToken is null, it means that there are no more videos
			if (nextPageToken == null)
				noMorePlaylistPages = true;
		} catch (IOException ex) {
			Log.e(TAG, ex.getLocalizedMessage());
		}
	}

	return toYouTubePlaylistList(playlistList);
}
 
Example #5
Source File: YouTubeRecyclerViewFragment.java    From YouTubePlaylist with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    if (getArguments() != null) {
        mPlaylistIds = getArguments().getStringArray(ARG_YOUTUBE_PLAYLIST_IDS);
    }

    // start fetching the playlist titles
    new GetPlaylistTitlesAsyncTask(mYouTubeDataApi) {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mProgressDialog.show();
        }
        
        @Override
        protected void onPostExecute(PlaylistListResponse playlistListResponse) {
            // if we didn't receive a response for the playlist titles, then there's nothing to update
            if (playlistListResponse == null)
                return;

            mPlaylistTitles = new ArrayList();
            for (com.google.api.services.youtube.model.Playlist playlist : playlistListResponse.getItems()) {
                mPlaylistTitles.add(playlist.getSnippet().getTitle());
            }
            // update the spinner adapter with the titles of the playlists
            ArrayAdapter<List<String>> spinnerAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, mPlaylistTitles);
            spinnerAdapter.setDropDownViewResource(SPINNER_ITEM_DROPDOWN_LAYOUT_ID);
            mPlaylistSpinner.setAdapter(spinnerAdapter);
            mProgressDialog.hide();
        }
    }.execute(mPlaylistIds);
}