About Playlists

About Playlists

Contents

Introduction

The Android 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.

Example

Create Playlist

  1. Add Cloud SDK for Android to an existing or a new Android project.
  2. Initialize the CloudAPI class object with the application key, secret and the callback URL you obtained from the ThingSpace portal.
  3. Authorize the application by calling CloudAPI#authorize().
  4. If you plan to add files to the playlist, call getFullview or search method to obtain information on files stored in the user’s Personal Cloud Storage.
  5. Create a playlist using this code sample.

Code Sample

String name; //new playlist name
ArrayList<String> paths; //paths of all the files to be added to this new playlist 
try {
    Playlist playlist = cloudAPI.createPlaylist(context, name, paths, PlaylistType.IMAGE);
    Log.d("Create Playlist", "New Playlist name: " + playlist.getName());
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
        Log.d("Create Playlist", "User not authorized, please call CloudAPI#authorize()");
    }
}```

### Delete Playlist

1. Add Cloud SDK for Android to an existing or a new Android project.
2. Initialize the Cloud SDK object.
3. Authorize the application by calling `CloudAPI#authorize()`.
4. Call [`getPlaylist`](../../Android_Reference/CloudAPI/) method to obtain a list of playlists and playlists' information.
5. Delete a playlist by using the code sample below.

**Code Sample**

**NOTE:** You can obtain the playlist UID by calling `Playlist#getUid(../Android_Reference/CloudAPI.md)` API.

```java
String uid;
try {
    boolean playlistDeleted = cloudAPI.deletePlaylist(context, uid);
    Log.d("Delete Playlist", "Playlist Deleted? :- " + playlistDeleted);
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHAURIZED) {
        Log.d("Delete Playlist", "User not authorized, please call CloudAPI#authorize()");
    }
}

Retrieve Playlist

  1. Add Cloud SDK for Android to an existing or a new Android project.
  2. Initialize the Cloud SDK object.
  3. Authorize the application by calling CloudAPI#authorize().
  4. Retrieve Playlists using this code sample.

Code Sample

try {
    ItemList<Playlist> playlistItemList = cloudAPI.getPlaylists(context, PlaylistType.MUSIC, SortType.NAME.setOrder(SortType.SortOrder.ASC));
    for (int i=0; i<playlistItemList.getCount(); i++) {
        Playlist playlist = playlistItemList.getItem(i);
        Log.d("Playlist", "Name: " + playlist.getName() + " - Type: " + playlist.getType());
    }
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
        Log.d("Retrieve Playlist", "User not authorized, please call CloudAPI#authorize()");
    }
}

Update Playlist

  1. Add Cloud SDK for Android to an existing or a new Android project.
  2. Initialize the Cloud SDK object.
  3. Authorize the application by calling CloudAPI#authorize().
  4. Call getPlaylist method to obtain a list of playlists and playlists’ information.
  5. Update a playlist by using the code sample below.

Code Sample

String uid; //Playlist uid as obtained from Playlist#getUid();
String name; //new playlist name
try {
    Playlist playlist = cloudAPI.updatePlaylist(context, uid, name);
    Log.d("Update Playlist", "Playlist name: " + playlist.getName());
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
        Log.d("Update Playlist", "User not authorized, please call CloudAPI#authorize()");
    }
}

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