0

由于某种原因,我所有的缩略图看起来都一样。我不确定我到底做错了什么,但我相信你们中的一个人可以发现问题(这是我第一次使用 Youtube API)

有什么建议么?

附言

我认为这可能与我使用 youTubeThumbnailView1 和 youTubeThumbnailView2 创建多个缩略图的事实有关——但是我觉得这可能不是正确的做法。

截屏:

http://i.stack.imgur.com/DEWKK.png

爪哇:

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubeThumbnailLoader;
import com.google.android.youtube.player.YouTubeThumbnailLoader.ErrorReason;
import com.google.android.youtube.player.YouTubeThumbnailView;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ScrollView;
import android.widget.Toast;

public class Home extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener,
YouTubeThumbnailView.OnInitializedListener {

    public static final String API_KEY = "AIzaSyC0Te2pyooXzuyLaE6_SsFlITKCwjj55fI";
    public static final String VIDEO_ID = "o7VVHhK9zf0";
    public static final String VIDEO1_ID = "xVHHJqntuXI";
    public static final String VIDEO2_ID = "YWteQj_q3Ro";

    private YouTubePlayer youTubePlayer;
    private YouTubePlayerView youTubePlayerView;
    private YouTubeThumbnailView youTubeThumbnailView1;
    private YouTubeThumbnailView youTubeThumbnailView2;

    private YouTubeThumbnailLoader youTubeThumbnailLoader;
    ScrollView mainScrollView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);

        youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtubeplayerview);
        youTubePlayerView.initialize(API_KEY, this);

        mainScrollView = (ScrollView)findViewById(R.id.groupScrollView);



        youTubeThumbnailView1 = (YouTubeThumbnailView) findViewById(R.id.youtubethumbnailview1);
        youTubeThumbnailView1.initialize(API_KEY, this);

        youTubeThumbnailView1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (youTubePlayer != null) {
                    youTubePlayer.cueVideo(VIDEO1_ID);
                    youTubePlayer.play();
                    mainScrollView.smoothScrollTo(0, 0);
                }
            }
        });




        youTubeThumbnailView2 = (YouTubeThumbnailView) findViewById(R.id.youtubethumbnailview2);
        youTubeThumbnailView2.initialize(API_KEY, this);

        youTubeThumbnailView2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg1) {
                if (youTubePlayer != null) {
                    youTubePlayer.cueVideo(VIDEO1_ID);
                    youTubePlayer.play();
                    mainScrollView.smoothScrollTo(0, 0);
                }
            }
        });
    }

    @Override
    public void onInitializationFailure(Provider provider,
            YouTubeInitializationResult result) {

    }

    @Override
    public void onInitializationSuccess(Provider provider,
            YouTubePlayer player, boolean wasRestored) {

        youTubePlayer = player;

        if (!wasRestored) {
            player.cueVideo(VIDEO_ID);
        }
    }

    @Override
    public void onInitializationFailure(YouTubeThumbnailView thumbnailView,
            YouTubeInitializationResult error) {

    }

    @Override
    public void onInitializationSuccess(YouTubeThumbnailView thumbnailView,
            YouTubeThumbnailLoader thumbnailLoader) {

        youTubeThumbnailLoader = thumbnailLoader;
        thumbnailLoader
        .setOnThumbnailLoadedListener(new ThumbnailLoadedListener());

        youTubeThumbnailLoader.setVideo(VIDEO_ID);

    }

    private final class ThumbnailLoadedListener implements
    YouTubeThumbnailLoader.OnThumbnailLoadedListener {

        @Override
        public void onThumbnailError(YouTubeThumbnailView arg0, ErrorReason arg1) {

        }

        @Override
        public void onThumbnailLoaded(YouTubeThumbnailView arg0, String arg1) {

        }

    }

}
4

2 回答 2

2

问题是这个功能:

 @Override
    public void onInitializationSuccess(YouTubeThumbnailView thumbnailView,
        YouTubeThumbnailLoader thumbnailLoader) {

    youTubeThumbnailLoader = thumbnailLoader;
    thumbnailLoader
    .setOnThumbnailLoadedListener(new ThumbnailLoadedListener());

    //You are always loading the thumbnail of VIDEO_ID
    youTubeThumbnailLoader.setVideo(VIDEO_ID);

}

您总是在加载 VIDEO_ID 的缩略图。您应该检查哪个视图已初始化。尝试这个:

@Override
public void onInitializationSuccess(YouTubeThumbnailView thumbnailView,
        YouTubeThumbnailLoader thumbnailLoader) {

    youTubeThumbnailLoader = thumbnailLoader;
    thumbnailLoader
    .setOnThumbnailLoadedListener(new ThumbnailLoadedListener());

    if (thumnailView.equals(youTubeThumbnailView1)
       youTubeThumbnailLoader.setVideo(VIDEO1_ID);
    else
       youTubeThumbnailLoader.setVideo(VIDEO2_ID);

}
于 2013-12-09T13:31:19.853 回答
0

看来您正在调用youTubePlayer.cueVideo(VIDEO1_ID);youTubeThumbnailView1 和 youTubeThumbnailView2。

于 2013-11-22T23:15:32.177 回答