如何通过 YouTube 的实时 API 获取我的直播密钥?



我使用自己的编码器来流式传输视频。当我流式传输时,我必须继续返回YouTube以更改所选的流密钥以使用创建的第一个流密钥。如何更改或确保 YoutTube API 使用原始流密钥而不生成新的流密钥。

我尝试使用列表,更新和转换,但没有一个响应提供流密钥或允许我更改正在使用的流密钥

title = getStreamTitle();
System.out.println("You chose " + title + " for stream title.");
// Create a snippet with the video stream's title.
LiveStreamSnippet streamSnippet = new LiveStreamSnippet();
streamSnippet.setTitle(title);


// Define the content distribution network settings for the
// video stream. The settings specify the stream's format and
// ingestion type. See:
// https://developers.google.com/youtube/v3/live/docs/liveStreams#cdn
CdnSettings cdnSettings = new CdnSettings();
cdnSettings.setFormat("1080p");
cdnSettings.setIngestionType("rtmp");
cdnSettings.getIngestionInfo();
LiveStream stream = new LiveStream();
stream.setKind("youtube#liveStream");
stream.setSnippet(streamSnippet);
stream.setCdn(cdnSettings);

// Construct and execute the API request to insert the stream.
YouTube.LiveStreams.Insert liveStreamInsert =
youtube.liveStreams().insert("snippet,cdn", stream);
LiveStream returnedStream = liveStreamInsert.execute();

这就是我目前正在做的事情,但这为 YouTube 广播活动创建了一个新流。我不希望它制作新流,但我需要返回密钥。

private static String getStreamTitle() throws IOException {
String title = "";
System.out.print("Please enter a stream title: ");
BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
title = bReader.readLine();
if (title.length() < 1) {
// Use "New Stream" as the default title.
title = "New Stream";
}
return title;
}

我要么希望输出给我一个可以添加到编码器中的流密钥,要么能够直接让它使用以前的流,以便可重用的流密钥保持不变。

对于那些还没有看过OP的新帖子的人,他们发布了他们的答案,您可以使用以下方法获取流密钥:

returnedStream.getCdn().getIngestionInfo().getStreamName();

如何通过 YouTube 直播 API 更改活动使用的直播?

最新更新