Increasing a Youtube Thumbnail Size

走远了吗. 提交于 2020-01-05 13:07:14

问题


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.



来源:https://stackoverflow.com/questions/20338602/increasing-a-youtube-thumbnail-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!