Alaa Agwa
Alaa Agwa

Reputation: 162

How to get the live stream youtube channel status?

Is there any way to get the status if it's ended or not of a live stream ? I got only the live stream id for this job.

Upvotes: 1

Views: 1789

Answers (3)

lory
lory

Reputation: 41

here is my code that I get broadcast and streaming status:

broadcast status get:

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);
        }
}

streaming status get:

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);
                }
        }

hope to help someone care about this question!

Upvotes: 2

Alaa Agwa
Alaa Agwa

Reputation: 162

This link should do the work

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

this link gives an info about the video or the stream. in my situation it gives me the live stream has ended.

Upvotes: 2

Pedro Lobito
Pedro Lobito

Reputation: 98861

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

You should receive a response similar to this:

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

Upvotes: 1

Related Questions