【发布时间】:2025-12-15 12:40:01
【问题描述】:
我使用自己的编码器流式传输视频。当我流式传输时,我必须继续返回 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;
}
我要么希望输出给我一个流密钥,我可以将它添加到我的编码器中,或者能够直接使它使用以前的流,这样可重用的流密钥保持不变。
【问题讨论】:
标签: java stream youtube-api youtube-livestreaming-api