【ANDROID】從YouTube播放列表中獲取所有視訊ID
我正在開發一個應用程式,顯示來自我自己的YouTube播放列表的YouTube視訊。我正在使用youtube android api來完成這項工作。我使用youtubethumbnailview來顯示視訊,當然我可以在一個youtubethumbnailview中獲取播放列表,但我正在尋找一種方法來從播放列表中獲取所有視訊並將它們儲存在字串陣列中,這樣我就可以建立一個listview來顯示所有視訊。
所以我唯一需要的就是身份證,然後我就可以讓這個工作了。我看了Video Wall演示,但找不到我需要的,除了我的nexus 7上的fc。
解決辦法
哎呀,我也打敗了你——)
http://blog.blundellapps.com/show-youtube-user-videos-in-a-listview/
您需要解析json陣列資料並獲得正確的字串。
像這樣的:
// 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));
}