I'm working on an app that shows YouTube video's from one of my own YouTube playlists. I'm using the YouTube Android API to get this done. I use YouTubeThumbnailView to show the video's, I can of course get the playlist in one YouTubeThumbnailView, but I'm looking for a way to get all the video's from the playlist and store them in a string array so I can create a ListView to show all video's.
So the only thing I need are the ID's, then I can get this working. I looked at the Video Wall demo but can't find what I need, beside that it FC on my Nexus 7.
Oops! beat you to it :-)
Link to Blog
You need to parse the JSON array data and get the correct string.
Something like this:
// For further information about the syntax of this request and JSON-C
// see the documentation on YouTube http://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html
// Get are search result items
JSONArray jsonArray = json.getJSONObject("data").getJSONArray("items");
// Create a list to store are videos in
List<Video> videos = new ArrayList<Video>();
// Loop round our JSON list of videos creating Video objects to use within our app
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
// The title of the video
String title = jsonObject.getString("title");
// The url link back to YouTube, this checks if it has a mobile url
// if it doesnt it gets the standard url
String url;
try {
url = jsonObject.getJSONObject("player").getString("mobile");
} catch (JSONException ignore) {
url = jsonObject.getJSONObject("player").getString("default");
}
// A url to the thumbnail image of the video
// We will use this later to get an image using a Custom ImageView
// Found here http://blog.blundellapps.com/imageview-with-loading-spinner/
String thumbUrl = jsonObject.getJSONObject("thumbnail").getString("sqDefault");
// Create the video object and add it to our list
videos.add(new Video(title, url, thumbUrl));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With