Reputation: 75
I'm attempting to use YouTubeThumbnailView to setup multiple thumbnails for a series of youtube videos. The problem is the same thumbnail is repeated over an over so I'm looking for an example of how this can be accomplished.
I've attempted to google search the issue but I've only been able to find examples with one thumbnail - I'm simply looking for an example of how to setup more than one (correctly).
YouTube API does not play videos as expected
Upvotes: 2
Views: 4598
Reputation:
Activity
public class TestActivity extends AppCompatActivity {
private static final String API_KEY = "AIzTjlIUpkoRVgchvcCzW1Aebi0PqJU_ak";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
final YouTubeThumbnailView youTubeThumbnailView = (YouTubeThumbnailView) findViewById(R.id.youtubethumb_id);
youTubeThumbnailView.setTag("UwTuL-PWxXw");
youTubeThumbnailView.initialize(API_KEY, new YouTubeThumbnailView.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, final YouTubeThumbnailLoader youTubeThumbnailLoader) {
youTubeThumbnailLoader.setVideo(youTubeThumbnailView.getTag().toString());
youTubeThumbnailLoader.setOnThumbnailLoadedListener(new YouTubeThumbnailLoader.OnThumbnailLoadedListener() {
@Override
public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
youTubeThumbnailLoader.release();
}
@Override
public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader.ErrorReason errorReason) {
}
});
}
@Override
public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {
}
});
}}
xml
<com.google.android.youtube.player.YouTubeThumbnailView
android:id="@+id/youtubethumb_id"
android:layout_width="match_parent"
android:layout_height="@dimen/_150sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Upvotes: 0
Reputation: 111
I know your question was posted a long time ago, but for someone who will try to find solution later.
YouTubeThumbnailView youTubeThumbnailView;
LinearLayout ll = new LinearLayout(this);
for(int i = 0 ; i < videos.length ; i++){
final String videoID = videos[i];
youTubeThumbnailView = new YouTubeThumbnailView(this);
youTubeThumbnailView.setTag(videoID);
youTubeThumbnailView.initialize(API_KEY, this);
ll.addView(youTubeThumbnailView);
}
and for initialization
@Override
public void onInitializationSuccess(YouTubeThumbnailView thumbnailView,
YouTubeThumbnailLoader thumbnailLoader) {
youTubeThumbnailLoader = thumbnailLoader;
thumbnailLoader.setOnThumbnailLoadedListener(new ThumbnailLoadedListener());
youTubeThumbnailLoader.setVideo(thumbnailView.getTag().toString());
}
Upvotes: 9