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.35k
    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.

    1. <com.google.android.youtube.player.YouTubeThumbnailView
    2. android:id="@+id/youtube_view"
    3. android:layout_width="match_parent"
    4. android:layout_height="180dp"
    5. android:layout_marginBottom="@dimen/ten_dp"
    6. android:visibility="gone"/>
    1. // Initializing video player with developer key
    2. youtube_view.initialize(Config.DEVELOPER_KEY, new YouTubeThumbnailView.OnInitializedListener() {
    3.  
    4. @Override
    5. public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, final YouTubeThumbnailLoader youTubeThumbnailLoader) {
    6.  
    7. youTubeThumbnailLoader.setVideo(videoId);
    8.  
    9. youTubeThumbnailLoader.setOnThumbnailLoadedListener(new YouTubeThumbnailLoader.OnThumbnailLoadedListener() {
    10. @Override
    11. public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
    12.  
    13. youTubeThumbnailLoader.release();
    14. Toast.makeText(getActivity(), "It's a valid youtube url.", Toast.LENGTH_SHORT).show();
    15. }
    16.  
    17. @Override
    18. public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader.ErrorReason errorReason) {
    19. try {
    20.  
    21. Toast.makeText(getActivity(), "Not a valid youtube url.", Toast.LENGTH_SHORT).show();
    22. } catch (Exception ex) {
    23. ex.printStackTrace();
    24. }
    25. }
    26. });
    27. }
    28.  
    29. @Override
    30. public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {
    31.  
    32. }
    33. });

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: