Get Help

programatic method to check if a stream is online

Find or share Ustream API Scripts and code snippets for web sites or apps.
Forum rules
Please take a moment to read the rules before sharing any scripts or replying to any posts in this forum.

programatic method to check if a stream is online

Postby a2liter » Wed Dec 29, 2010 8:20 am

I have just started using the ustream producer to feed video to a web site where i have used the embed code. what I would like to be able to do is check to see if stream is active when someone loads the page prior to loading the embed code. I want to be able to display an "offline" message instead of the ustream player when the stream is offline. Is there a method for querying to see if a stream is active, via URL or API or something?
a2liter
 
Posts: 2
Joined: Tue Dec 28, 2010 1:21 pm

Sponsored Links

Postby Sponsored Links » Fri Aug 27, 2004 12:01 am


Sponsored Links
VP of Marketing
 
Posts: 10100
Joined: Fri Aug 27, 2004 12:01 am
Location: Mountain View, CA

Re: programatic method to check if a stream is online

Postby SnowPhoenix9999 » Wed Dec 29, 2010 9:45 am

Yes, there is an API you can use, and documentation is available here:
http://developer.ustream.tv

In your case, you'd probably want to use getValueOf/status, which will return either "offline" or "live".
SnowPhoenix9999
Team Leader
Team Leader
 
Posts: 92
Joined: Fri May 14, 2010 11:47 am

Re: programatic method to check if a stream is online

Postby a2liter » Wed Dec 29, 2010 10:07 am

Thanks for the info..

I am using the following url to test the live/offline status.

http://api.ustream.tv/html/channel/a2li ... eOf/status

I do get the information back but there is a HUGE delay from when I actually go live or go offline before the information that the API returns is updated. I am talking about a 30 to 60 second lag from when I go online or offline.

Is this normal?
a2liter
 
Posts: 2
Joined: Tue Dec 28, 2010 1:21 pm

Re: programatic method to check if a stream is online

Postby kmatyi86 » Sun Jun 09, 2013 10:14 am

I wrote a function in php which returns Live now/Offline/Error for a given ustream channel.

function liveornot($channelID) {
$UstStatusURL = "http://api.ustream.tv/php/channel/".$channelID."/getValueOf/status?key=FD7735302BA6E894D1FFB1C9BE2FEBD4";
$UstStatusSerial = file_get_contents($UstStatusURL);
$UstStatusArray = unserialize($UstStatusSerial);
switch ( $UstStatusArray['results'] ) {
case 'live':
$status = 'Live now';
break;
case 'offline':
$status = 'Offline';
break;
case 'error':
$status = 'Error.';
break;
}
return $status;
}

You just have to insert the next line in your code:

$chID = paste_here_your_ustream_channel_ID;
echo liveornot($chID);
kmatyi86
 
Posts: 1
Joined: Sun Jun 09, 2013 8:10 am
Location: Cluj-Napoca


Return to Ustream API Scripts

Who is online

Users browsing this forum: No registered users and 1 guest