What is the easiest way to get the title of a single YouTube video in Android? I'm using the Android YouTube API to play video's but they don't return a title cause it only supports playback options. The only thing I need is to display the title of the video, I obviously have the video ID itself but I don't have a clue where to start.
Things I looked at:
For some reason I find it hard to understand how to use them and this seems like a really simple action to me. I'm curious if there is an easier option or if there is someone who can help me get on the right track with this.
You can use this code for this purpose.
public class SimpleYouTubeHelper {
public static String getTitleQuietly(String youtubeUrl) {
try {
if (youtubeUrl != null) {
URL embededURL = new URL("http://www.youtube.com/oembed?url=" +
youtubeUrl + "&format=json"
);
return new JSONObject(IOUtils.toString(embededURL)).getString("title");
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With