Creates thumbnail url for a given youtube video ID. - Android Graphics

Android examples for Graphics:Bitmap Thumbnail

Description

Creates thumbnail url for a given youtube video ID.

Demo Code


//package com.java2s;

public class Main {
    public static final String THUMBNAIL_QUALITY_DEFAULT = "default";
    public static final String THUMBNAIL_QUALITY_MQ = "mqdefault";
    public static final String THUMBNAIL_QUALITY_HQ = "hqdefault";
    public static final String THUMBNAIL_QUALITY_SD = "sddefault";

    /**//from  w  ww .ja v a2  s.com
     * Creates thumbnail url for a given video ID.
     *
     * @param videoId
     * @param quality
     **/
    public static String createThumbnailUrl(String videoId, String quality) {

        if (quality == null) {
            quality = THUMBNAIL_QUALITY_DEFAULT;
        }

        if (!quality.equalsIgnoreCase(THUMBNAIL_QUALITY_DEFAULT)
                && !quality.equalsIgnoreCase(THUMBNAIL_QUALITY_MQ)
                && !quality.equalsIgnoreCase(THUMBNAIL_QUALITY_HQ)
                && !quality.equalsIgnoreCase(THUMBNAIL_QUALITY_SD)) {
            throw new IllegalArgumentException(
                    "Invalid quality thumbnail requested");
        }

        return "http://img.youtube.com/vi/" + videoId + "/" + quality
                + ".jpg";
    }
}

Related Tutorials