如何获得直播youtube频道状态?

时间:2015-09-28 22:15:09

标签: youtube-api youtube-data-api

如果现场直播结束或未结束,有没有办法获得状态?我只获得了这份工作的实时流ID。

3 个答案:

答案 0 :(得分:2)

这是我获得广播和流媒体状态的代码:

广播状态获取:

liveStreamRequest = youtube.liveStreams()
        .list("id,status")
        .setId(liveBroadcast.getContentDetails()
                .getBoundStreamId());
LiveStreamListResponse returnedList = liveStreamRequest.execute();
List<LiveStream> liveStreams = returnedList.getItems();
if (liveStreams != null && liveStreams.size() > 0) {
    LiveStream liveStream = liveStreams.get(0);
    if (liveStream != null)
        while (!liveStream.getStatus().getStreamStatus()
                .equals("active")) {
            Thread.sleep(1000);
            returnedList = liveStreamRequest.execute();
            liveStreams = returnedList.getItems();
            liveStream = liveStreams.get(0);
        }
}

流媒体状态获取:

liveBroadRequest = youtube.liveBroadcasts().list("id,status");
        liveBroadRequest.setBroadcastStatus("all");

        LiveBroadcastListResponse liveBroadcastResponse = liveBroadRequest.execute();
        List<LiveBroadcast> returnedList = liveBroadcastResponse.getItems();
        if (returnedList != null && returnedList.size() > 0) {
            liveBroadcastReq = returnedList.get(0);
            if (liveBroadcastReq != null)
                while (!liveBroadcastReq.getStatus().getLifeCycleStatus().equals("testing")) {
                    Thread.sleep(1000);
                    AppLog.d("Error","publish broadcast - getLifeCycleStatus: " + liveBroadcastReq.getStatus().getLifeCycleStatus());
                    liveBroadcastResponse = liveBroadRequest.execute();
                    returnedList = liveBroadcastResponse.getItems();
                    liveBroadcastReq = returnedList.get(0);
                }
        }

希望能帮助有人关心这个问题!

答案 1 :(得分:1)

GET https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Csnippet%2Cstatus&mine=true&broadcastStatus=active&key={YOUR_API_KEY}

您应该会收到与此相似的回复:

{ "status": { "lifeCycleStatus": "live"}}

答案 2 :(得分:1)

此链接应该完成工作

https://www.youtube.com/get_video_info?el=detailpage&hl=en&ps=default&video_id={stream or video id}

此链接提供有关视频或流的信息。在我的情况下,它让我的直播已经结束。