gpt4 book ai didi

android - Youtube Player与Android App中的缩略图集成

转载 作者:行者123 更新时间:2023-12-03 06:10:55 29 4
gpt4 key购买 nike

嗨,我遵循CodingwithMitch上有关在Android中使用Youtube API的教程。这是一个很好的入门教程。
一切运行正常,但是当播放器闲置时,屏幕只是空白,而不显示视频缩略图/预览。
screenshot of my app

我想让待机屏幕显示vid缩略图,以便我知道将播放什么视频。

MyActivity.xml中的代码如下:

<view                    class="com.google.android.youtube.player.YouTubePlayerView"
android:id="@+id/youtubePlay"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical"

YouTube配置代码:
public class YouTubeConfig {public YouTubeConfig() {} private static final String API_KEY = "AIzaSyXXXXXX";public static String getApiKey(){
return API_KEY;}}

在我的MainActivity.java中
private static final String TAG = "MainActivity";
YouTubePlayerView mYoutubePlayerView;
Button btnPlay;
YouTubePlayer.OnInitializedListener mOnInitializedListener;


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


//PlayYouTube
Log.d(TAG, "onCreate: Starting.");
btnPlay = (Button) findViewById(R.id.btnPlay);
mYoutubePlayerView = (YouTubePlayerView) findViewById(R.id.youtubePlay);
mOnInitializedListener = new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
Log.d(TAG, "onInitializationSuccess: Done Initialising.");
youTubePlayer.loadPlaylist("PLZRTg9sNaMaFnh04-HODVcYRlFtKO8rsS");
}

@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.d(TAG, "onInitializationSuccess: Fail to Initialize.");
}
};
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick: Initializing Youtube Player.");
mYoutubePlayerView.initialize(YouTubeConfig.getApiKey(), mOnInitializedListener);
}
});

任何帮助将非常感激

最佳答案

您需要提供要显示其预览的youtube视频的缩略图。
Get a thumbnail from youtube video

关于android - Youtube Player与Android App中的缩略图集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54094389/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com