我正在 Java 中使用 YouTube Live Streaming API。 我有时会遇到一个问题。
我编写了一个类,用于检索现有的直播流并创建直播,确保该流正在发送数据,然后将它们绑定(bind)在一起,然后我发出 2 个转换请求。
首先我过渡到测试(实时预览)请求,然后我过渡到实时请求, https://developers.google.com/youtube/v3/live/life-of-a-broadcast 上的手册第 4.1 节说 我应该轮询 API,直到广播生命周期状态更改为实时
这是我写的: '''
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);
}
''' 有时它工作顺利,但有时状态没有改变,这意味着广播不会转换为直播,我陷入无限循环。 当然我可以手动跳出循环,但我仍然不明白为什么请求没有被处理以及我可以修复它吗?
最佳答案
为什么要查找状态 liveStarting
而不是 live
?超时可能会变得不幸并且完全错过状态。 liveStarting
是一个过渡状态。
https://developers.google.com/youtube/v3/live/docs/liveBroadcasts#status.lifeCycleStatus
我还建议查看 LiveBroadcast
资源上的 contentDetails.enableAutoStart
属性。
您可以在附加LiveStream
之前将LiveBroadcast
更新为enableAutoStart: true
。我发现这是一种更可靠的启动流的方式。
https://developers.google.com/youtube/v3/live/docs/liveBroadcasts#contentDetails.enableAutoStart
关于java - 对实时转换请求没有回应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58745608/