Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create youtube video thumbnail in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.31k
    Comment on it

    In order to create youtube video thumbnail in android we have to first initialize its view i.e. YouTubeThumbnailView in our xml file. On initializing YoutubeThumbnailView we have to add developer key and its InitializationSuccess listener with two override methods onThumbnailLoaded and onThumbnailError. Finally on youTubeThumbnailLoader we have to add setVideo method in which we have to pass video id. Below example will let you know how to implement this in android.

    <com.google.android.youtube.player.YouTubeThumbnailView
                        android:id="@+id/youtube_view"
                        android:layout_width="match_parent"
                        android:layout_height="180dp"
                        android:layout_marginBottom="@dimen/ten_dp"
                        android:visibility="gone"/>
    // Initializing video player with developer key
       youtube_view.initialize(Config.DEVELOPER_KEY, new YouTubeThumbnailView.OnInitializedListener() {
    
          @Override
          public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, final YouTubeThumbnailLoader youTubeThumbnailLoader) {
    
             youTubeThumbnailLoader.setVideo(videoId);
    
             youTubeThumbnailLoader.setOnThumbnailLoadedListener(new YouTubeThumbnailLoader.OnThumbnailLoadedListener() {
                 @Override
                 public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
    
                     youTubeThumbnailLoader.release();
                     Toast.makeText(getActivity(), "It's a valid youtube url.", Toast.LENGTH_SHORT).show();
                 }
    
                 @Override
                 public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader.ErrorReason errorReason) {
                     try {
    
                             Toast.makeText(getActivity(), "Not a valid youtube url.", Toast.LENGTH_SHORT).show();
                         } catch (Exception ex) {
                              ex.printStackTrace();
                         }
                    }
                   });
                 }
    
                 @Override
                 public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {
    
                }
           });

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: