gpt4 book ai didi

android - 在 android 中集成 youtube channel

转载 作者:行者123 更新时间:2023-11-30 02:36:03 24 4
gpt4 key购买 nike

我想在 android 中集成 youtube channel ,这样当用户打开 channel 时,它会显示该 channel 的所有视频。下面是将 youtube 视频集成到 android 的工作代码。这里我在 loadVideo() 中提供视频 ID方法。但我不知道如何整合 channel 。我想知道如何进行整合?

public class YoutubeActivity2 extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {

private YouTubePlayer YPlayer;
private static final String YoutubeDeveloperKey = "";
private static final int RECOVERY_DIALOG_REQUEST = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_you_tube_api);
final ActionBar ab = getActionBar();
ab.hide();
YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(YoutubeDeveloperKey, this);
}

@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult errorReason) {
if (errorReason.isUserRecoverableError()) {
errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
} else {
String errorMessage = String.format(
"There was an error initializing the YouTubePlayer",
errorReason.toString());
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RECOVERY_DIALOG_REQUEST)
{

getYouTubePlayerProvider().initialize(YoutubeDeveloperKey, this);
}
}

protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerView) findViewById(R.id.youtube_view);
}

@Override
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
YPlayer = player;
YPlayer.setFullscreen(true);
YPlayer.loadVideo("2zNSgSzhBfM");
YPlayer.play();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

最佳答案

您需要调用 API 来获取 channel 中的所有视频。

这是一个例子:https://github.com/youtube/yt-direct-lite-android/blob/master/app/src/main/java/com/google/ytdl/MainActivity.java#L391

关于android - 在 android 中集成 youtube channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26533239/

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