Bu, birisine yardımcı olabilir. Buradaki fikir ilk önce istediğiniz videoları almaktır. Burada bir oynatma listesinden videoların listesini aldım. Bundan sonra bu sınıfı kullandım:
Küçük resim web'den alınırken bir ilerleme çubuğu görüntülemek için.
/***
* Fetch all videos in a playlist
* @param playlistId
* @return
* @throws ClientProtocolException
* @throws IOException
* @throws JSONException
*/
public YouTubePlaylist fetchPlaylistVideos(String playlistId) throws ClientProtocolException, IOException, JSONException {
String playlistUrl = "https://gdata.youtube.com/feeds/api/playlists/" + playlistId + "?v=2&alt=jsonc";
HttpClient client = new DefaultHttpClient();
HttpUriRequest request = new HttpGet(playlistUrl);
HttpResponse response = client.execute(request);
String jsonString = GeneralHelpers.convertToString(response.getEntity().getContent());
JSONObject json = new JSONObject(jsonString);
if (jsonString.contains("Playlist not found")) {
Log.e(TAG, "playlist not found. id: " + playlistId);
return null;
}
JSONArray jsonArray = json.getJSONObject("data").getJSONArray("items");
String playlistTitle = json.getJSONObject("data").getString("title");
String author = json.getJSONObject("data").getString("author");
List<YouTubeVideo> videos = new ArrayList<YouTubeVideo>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject video = jsonArray.getJSONObject(i).getJSONObject("video");
// The title of the video
String title = video.getString("title");
String url;
try {
url = video.getJSONObject("player").getString("mobile");
} catch (JSONException ignore) {
url = video.getJSONObject("player").getString("default");
}
String thumbUrl = video.getJSONObject("thumbnail").getString("sqDefault");
String videoId = video.getString("id");
String uploaded = video.getString("uploaded");
String duration = video.getString("duration");
String minutes = (Integer.parseInt(duration)/60 < 10) ? "0" + (Integer.parseInt(duration)/60) : "" + (Integer.parseInt(duration)/60);
String seconds = (Integer.parseInt(duration) % 60 < 10) ? "0" + (Integer.parseInt(duration) % 60): "" + (Integer.parseInt(duration) % 60);
duration = minutes + ":" + seconds;
videos.add(new YouTubeVideo(title, author, url, thumbUrl, videoId, uploaded, duration));
}
YouTubePlaylist playlist = new YouTubePlaylist(author, playlistId, playlistTitle, videos);
return playlist;
}//end fetchPlaylistVideos
deneyin? – simchona
Nasıl çalışmıyor? SO size sadece spesifik olmayan problemlere cevap vermez. – simchona
Biliyorum bilmek mümkün mü değil mi? – Krishna