【问题标题】:Get all video id's from YouTube playlist从 YouTube 播放列表中获取所有视频 ID
【发布时间】:2012-12-28 12:14:54
【问题描述】:

我正在开发一款应用,它可以显示我自己的一个 YouTube 播放列表中的 YouTube 视频。我正在使用 YouTube Android API 来完成这项工作。我使用 YouTubeThumbnailView 来显示视频,我当然可以在一个 YouTubeThumbnailView 中获取播放列表,但我正在寻找一种方法来从播放列表中获取所有视频并将它们存储在一个字符串数组中,这样我就可以创建一个 ListView 来显示所有视频的。

所以我唯一需要的是 ID,然后我就可以让它工作了。我查看了Video Wall 演示,但找不到我需要的东西,除了它在我的 Nexus 7 上的 FC。

【问题讨论】:

    标签: android youtube-api


    【解决方案1】:

    哎呀!打败你:-)

    Link to Blog

    您需要解析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));
            }
    

    【讨论】:

    猜你喜欢
    • 2013-09-12
    • 2015-01-06
    • 2015-08-20
    • 2017-06-09
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2015-07-05
    相关资源
    最近更新 更多