Increasing a Youtube Thumbnail Size

2019-07-23 15:37发布

问题:

I've imported the source from the following tutorial:

http://blog.blundell-apps.com/show-youtube-user-videos-in-a-listview/

https://github.com/blundell/YouTubeUserFeed/tree/master/res/layout

but I cannot seem to increase the size of the thumbnails - I've tried changing userVideoThumbImageView in my XML from:

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

to

    android:layout_width="80dip"
    android:layout_height="80dip"


    but it only seems to increase the size of the black space around the thumbnail. 

XML:


<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <com.blundell.tut.ui.widget.UrlImageView
        android:id="@+id/userVideoThumbImageView"
        android:layout_width="80dip"
        android:layout_height="80dip"
        android:contentDescription="YouTube video thumbnail"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/userVideoTitleTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Video Title Not Found" />

</LinearLayout>

SCREENSHOT:

回答1:

That tutorial isn't all that good in implementing asynchronous tasks. While runnables work fine, in Android an AsyncTask will provide more control.

Now, for the issue you are having, I believe that youtube provides thumbnails in various sizes, you seem to be pulling the small one. Using a larger one will help but will be slower.

In the class GetYouTubeUserVideosTask, you'll find the line of code

String thumbUrl = jsonObject.getJSONObject("thumbnail").getString("sqDefault");

It it pulling the Standard Quality image from the JSON being received, you should use the High Quality image. That can be achieved by changing to

String thumbUrl = jsonObject.getJSONObject("thumbnail").getString("hqDefault");

You can do a sample request and see the data at anytime by looking at the url being used, the return looks parcially like this:

"thumbnail":{"sqDefault":"https://i.ytimg.com/vi/NnL0QOtK-o8/default.jpg","hqDefault":"https://i.ytimg.com/vi/NnL0QOtK-o8/hqdefault.jpg"}

That way you know you have various options.