I' am working on app that's get content from blog pages as jsoup nodes/elements, some pages contains youtube embedded tag iframe
like this
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/VXD6a_LgBaQ/0.jpg" frameborder="0" height="400" src="https://www.youtube.com/embed/VXD6a_LgBaQ?feature=player_embedded" width="600"></iframe>
I'm looking for a way to replace any iframe youtube tags with imageView and display the thumbnail on it, that's when the user clicks on the image, the application opens the YouTube application through it intent and view the video.
I found answer someone here , he could replace img tags with Image Views, I succeed on get youtube link and thumbnail and view the image on ImageView
Element element = document.body();
String youtubeThumbnailImageSrc = element.getElementsByClass
("YOUTUBE-iframe-video").attr("data-thumbnail-src");
String youTubeLink =
element.getElementsByClass("YOUTUBE-iframe-video").attr("src");
Log.e("YouTube thumbnail", youtubeThumbnailImageSrc);
Log.e("Youtube link", youTubeLink);
if (youtubeThumbnailImageSrc.isEmpty()) {
youtubeThumbnailImagesetVisibility = 8;
intent.putExtra("youtubeThumbnailImagesetVisibility",
youtubeThumbnailImagesetVisibility);
} else {
intent.putExtra("youTubeThumbnail", youtubeThumbnailImageSrc);
intent.putExtra("youTubeLink", youTubeLink);
}
the destination it's supposed to be like this
When you call
String youtubeThumbnailImageSrc = element.getElementsByClass
("YOUTUBE-iframe-video").attr("data-thumbnail-src");
You will get value of attribute only for the first element.
You need to iterate manually to get all links:
for (Element e : element.getElementsByClass
("YOUTUBE-iframe-video")) {
String youtubeThumbnailImageSrc = e.attr("data-thumbnail-src");
System.out.println(youtubeThumbnailImageSrc);
}
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