Ray*_*d P 6 android youtube-api
我正在制作一个应用程序,可以从我自己的YouTube播放列表中显示YouTube视频.我正在使用YouTube Android API完成此操作.我使用YouTubeThumbnailView显示视频,我当然可以在一个YouTubeThumbnailView中获取播放列表,但我正在寻找一种方法从播放列表中获取所有视频并将它们存储在字符串数组中,这样我就可以创建一个ListView来显示所有视频.
所以我唯一需要的是ID,然后我可以让它工作.我查看了视频墙演示,但除了它在我的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));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7152 次 |
| 最近记录: |