【发布时间】:2020-03-03 20:23:29
【问题描述】:
我在 Java 中使用 YouTube Live Streaming API。 我有一个问题,有时会发生。
我编写了一个类来检索现有的直播流并创建一个直播,确保该流正在发送数据,然后将它们绑定在一起,然后我发出 2 个转换请求。
首先我转换到测试(实时预览)请求,然后我转换到实时请求, https://developers.google.com/youtube/v3/live/life-of-a-broadcast 的手册第 4.1 节说 我应该轮询 API,直到广播生命周期状态变为 live
这是我写的: '''
YouTube.LiveBroadcasts.Transition requestLive = CreateYouTube.getYoutube().liveBroadcasts()
.transition("live", returnedBroadcast.getId(), "snippet,status");
returnedBroadcast = requestLive.execute();
//poll while live starting (wait while starting live)
while(returnedBroadcast.getStatus().getLifeCycleStatus().equals("liveStarting")) {
returnedBroadcast = getBroadcastById(returnedBroadcast.getId());
System.out.println("polling liveStarting "+args[0]);
Thread.sleep(1000);
}
''' 有时它工作顺利,但有时状态没有改变,这意味着广播没有转换到直播,我陷入了无限循环。 当然我可以手动跳出循环,但我仍然不明白为什么请求没有被处理,我可以修复它。
【问题讨论】:
标签: java youtube-api youtube-data-api youtube-livestreaming-api