About Playlists

About Playlists

Contents

Introduction

The Java SDK allows you to access Personal Cloud Storage account holder’s data to retrieve, create, edit, modify, and delete playlists. Supported types of playlists include image, music, video, and image-video playlists. The following examples provide detailed steps that describe how to use supported methods and include code samples to help you get started with playlists.

Examples

getPlaylists

getPlaylists method allows you to retrieve a list of the user’s playlists. You can filter the response by the playlist type and specify descending or ascending sort order. Other sort options include name, type, versionCreated, size, extension, album, artist, captureDate, compilation, contentType, creationDate, favorite, genre, height, modificationDate, priority, source, tags, title, and timelineDate.

This example retrieves playlists of type music, sorted by playlist name, and listed in the ascending order.

NOTE: Only a subset of playlists are returned for each call. Call the method in a loop until all playlists that match the specified criteria are retrieved.

Code Sample

public List<PlaylistDefinition> playlists(OAuthToken token)
{
    CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
    CloudClientContext context = new CloudClientContext(app, token);
    CloudClient client = new CloudClient(context);

// retrieve one page (up to 100) of music playlists, sorted by ascending playlist name.

    List<PlaylistDefinition> list = new ArrayList<>();
    try
    {
        int count, page = 1, pageSize = 100;
        do
        {
            PlaylistDefinitions defs = client.getPlaylists("music", page++, pageSize, "name+asc");
            list.addAll(defs.getPlaylistDefinitions());
            count = defs.getCount();
        }
        while (list.size() < count);
    }
    catch (CloudHttpException e) {
        System.out.println("bad HTTP response");
    }
    catch (IOException e) {
        System.out.println("network error, or failure to interpret json-encoded response");
    }
    return list;
}

getPlaylistItems

getPlaylistItems retrieves detailed information for all the items in a playlist.

This example uses the playlistUid retrieved via a call to getPlaylists in previous example.

Code Sample

public List<PlaylistItem> playlistItems(OAuthToken token, String playlistUid)
{
    CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
    CloudClientContext context = new CloudClientContext(app, token);
    CloudClient client = new CloudClient(context);

// retrieve one page (up to 100) playlist items, sorted by ascending item name

    List<PlaylistItem> list = new ArrayList<>();
    try
    {
        int count, page = 1, pageSize = 100;
        do
        {
            PlaylistItems items = client.getPlaylistItems(playlistUid, page++, pageSize, "name+asc");
            list.addAll(items.getItems());
            count = items.getTotalCount();
        }
        while (list.size() < count);
    }
    catch (CloudHttpException e) {
        System.out.println("bad HTTP response");
    }
    catch (IOException e) {
        System.out.println("network error, or failure to interpret json-encoded response");
    }
    return list;
}

postPlaylistItems

postPlaylistItems method adds items to the specified playlist.

You can also add items to a playlist by specifying them when you create a playlist or use putPlaylistItems to completely replace the set of items in a playlist with a new set of items.

Code Sample

public List<PlaylistDefinitionPath> addPlaylistItems(OAuthToken token, String playlistUid, List<String> paths)
{
    CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
    CloudClientContext context = new CloudClientContext(app, token);
    CloudClient client = new CloudClient(context);

    try
    {
        return client.postPlaylistItems(playlistUid, paths);
    }
    catch (CloudHttpException e) {
        System.out.println("bad HTTP response");
    }
    catch (IOException e) {
        System.out.println("network error, or failure to interpret json-encoded response");
    }
    return null;
}

getPlaylistItem

getPlaylistItem retrieves the binary content of a specific item in a playlist.

Code Sample

public InputStream playlistItem(OAuthToken token, String playlistUid, String itemUid)
{
    CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
    CloudClientContext context = new CloudClientContext(app, token);
    CloudClient client = new CloudClient(context);

    try
    {
        ContentTypedStream item = client.getPlaylistItem(playlistUid, itemUid);
        return item.getContent();
    }
    catch (CloudHttpException e) {
        System.out.println("bad HTTP response");
    }
    catch (IOException e) {
        System.out.println("network error, or failure to interpret json-encoded response");
    }
    return null;
}

Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.