Wednesday, 16 January 2019

How to replace youtube iframe tag or thumbnails with ImageViews

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



from How to replace youtube iframe tag or thumbnails with ImageViews

No comments:

Post a Comment