I want to know how to change YouTube thumbnail dynamically using Android YouTube api

Asked 1 years ago, Updated 1 years ago, 86 views

I'm making the same app as NAVER Cafe app. If a user who uses my app enters the YouTube URL in the edit text and presses the button, it would be nice to see the thumbnail below.

If you enter thumbnail url as code when you first create, you can see the thumbnail, but it doesn't change dynamically. I searched Stack Overflow or Google, but I couldn't find the data, so I asked.

Let me make a partial extract.


public class LinkDialog extends Dialog implements YouTubeThumbnailView.OnInitializedListener{

private String VIDEO_ID = "fqGSJVmX9Jw";

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 

  youTubeThumbView = (YouTubeThumbnailView) findViewById(R.id.youtube_dialog_tv);
        youTubeThumbView.initialize(API_KEY, this);


//Add button
addBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //linkTxt is the address value entered by the user
                linkTxt = linkEt.getText().toString();
                // Link extraction
                thumbnailTxt = linkTxt.split("/");

                // You tried to change the thumbnail here. But there is no mediating factor for the onInitializationSuccess method
                youTubeThumbnailLoader.setVideo(thumbnailTxt[2]);

        });


 @Override
    public void onInitializationSuccess(YouTubeThumbnailView thumbnailView, YouTubeThumbnailLoader thumbnailLoader) {
        youTubeThumbnailLoader = thumbnailLoader;
        thumbnailLoader.setOnThumbnailLoadedListener(new ThumbnailLoadedListener());

        //You are always loading the thumbnail of VIDEO_ID
        youTubeThumbnailLoader.setVideo(VIDEO_ID);

    }

    @Override
    public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {

    }

    private final class ThumbnailLoadedListener implements  YouTubeThumbnailLoader.OnThumbnailLoadedListener {

        @Override
        public void onThumbnailError(YouTubeThumbnailView arg0, YouTubeThumbnailLoader.ErrorReason arg1) {

        }

        @Override
        public void onThumbnailLoaded(YouTubeThumbnailView arg0, String arg1) {

        }

    }

android youtube

2022-09-21 16:53

1 Answers

It's a self-answer.

I couldn't do it, so I brought the thumbnail to the glide library.

I'd appreciate it if you could give me a hint if you know how to implement it with YouTube api.


2022-09-21 16:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.