我知道我可以在 YoutubePlayer StateChangeListener 的 onLoaded(( 方法中获取视频 ID,如下所示:
@Override
public void onLoaded(String s) {
// 's' contains Video ID
}
但现在只是一个实验,我想知道我怎么能得到视频标题......
更新
@Override
public void onLoaded(String s) {
// 's' contains Video ID
Toast.makeText(YouTubeViewActivity.this, s, Toast.LENGTH_SHORT).show();
String youtubeUrl = "https://www.youtube.com/watch?v=" + s;
Toast.makeText(YouTubeViewActivity.this, youtubeUrl, Toast.LENGTH_SHORT).show();
try {
if (youtubeUrl != null) {
Toast.makeText(YouTubeViewActivity.this, "Found URL", Toast.LENGTH_SHORT).show();
URL embededURL = new URL("http://www.youtube.com/oembed?url=" + youtubeUrl + "&format=json");
strTitle = new JSONObject(IOUtils.toString(embededURL)).getString("title");
Toast.makeText(YouTubeViewActivity.this, strTitle, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
这是怎么做的
String video_title;
@Override
public void onLoaded(String s) {
String youtubeUrl = "https://www.youtube.com/watch?v=" + s;
try {
if (youtubeUrl != null) {
URL embededURL = new URL("http://www.youtube.com/oembed?url=" +
youtubeUrl + "&format=json");
video_title = new JSONObject(IOUtils.toString(embededURL)).getString("title");
}
} catch (Exception e) {
e.printStackTrace();
}
}