I writing an app where i want to display a list of YouTube videos. But I want the list to display the video title with some other info but also show a thumbnail of the video
This question is old, but it is still coming in the top Google's search answers, so this us how I did it with the Android YouTube API.
YouTubeThumbnailView thumbnail = findViewById(R.id.thumbnail);
thumbnail.initialize(YOUTUBE_API_KEY, new YouTubeThumbnailView.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView,
YouTubeThumbnailLoader youTubeThumbnailLoader) {
youTubeThumbnailLoader.setVideo(youtubeID);
youTubeThumbnailLoader.setOnThumbnailLoadedListener(new YouTubeThumbnailLoader.OnThumbnailLoadedListener() {
@Override
public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
//need to release the loader!!!
youTubeThumbnailLoader.release();
}
@Override
public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView,
YouTubeThumbnailLoader.ErrorReason errorReason) {
//need to release the loader!!!
youTubeThumbnailLoader.release();
}
});
}
@Override
public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView,
YouTubeInitializationResult youTubeInitializationResult) {
//handle error here
}
});
YOUTUBE_API_KEY get your api key in here
youtubeID You need to use the video's ID not full URL.
Documentation here.