Twitch stream integration

Hello,
I’m making a website and i want to integrate most viewed twitch stream into my webpage, i did it succesfully but i have a little problem, i made 5 rows, each has two columns, in each column will be a twitch stream, and everything works fine except one thing. Whenever i press play i get spacing between rows, for a whole twitch stream column, and it goes like that whenever i press play.


Because im a new member i can only put one image for a post, but as u see at the pic i have spasing between rows and it goes up every time i press play. When i reload the page it goes normal

Im using this code:

Your Title Goes Here <?php /* Mucked together by Matt_Thomas @ Twitch.tv Was created in response to: https://discuss.dev.twitch.com/t/is-there-a-way-to-embed-twitch-on-your-site-so-that-only-the-most-viewed-streamer-plays/3309 This will take the $channels array list of users, find the streamer in your list ($channels) with the most viewers, then display it's stream. If none of the streamers are live, it will find the current twitch streamer with the most viewers instead. This can be modified easily to include any list of streamers. You can also change the fall back to be a specific game. Enjoy! Shoutouts to Kevo and https://discuss.dev.twitch.com/t/is-streamer-online-json-help-users-zigenzag-follows/946 - Where I started from. matt AT mrthomas DOT org */

/* Old unsupported API for team members: http://api.twitch.tv/api/team/teamkitty/all_channels.json - Might use this until kraken has team member listing, or until it changes */

$channels = array(“”); /* For now, we use a manually set list of streamers /
$callAPI = implode(“,”,$channels); /
Clean our list for next step /
$dataArray = json_decode(@file_get_contents(‘https://api.twitch.tv/kraken/streams?channel=’ . $callAPI), true); /
Pull the data from api.twitch.tv/kraken for each streamer in our list */

/* The query could just add ‘&limit=1’ since the API will return the streamers in order of highest viewers to lowest. This speeds things up./
/
$dataArray = json_decode(@file_get_contents(‘https://api.twitch.tv/kraken/streams?channel=’ . $callAPI . ‘&limit=1’), true); */

$max_viewers=0; /* Set a value to start stepping from /
$name='
** ERROR!!1! **'; / Set a value to name incase something goes wrong */

if ($dataArray[‘streams’] != null) { /* Make sure we get a response from the API /
foreach($dataArray[‘streams’] as $mydata){ /
Build an array with online streamers from our list /
if($mydata[‘_id’] != null){ /
Make sure the streamer has data in the API /
$viewers = $mydata[‘viewers’]; /
Store value of viewers from API as $viewers /
if ( $viewers > $max_viewers ) { /
Should always be more than 0 at this point /
$max_viewers = $viewers; /
Set new nonzero value to be $max_viewers and loop ‘foreach’ until we have the highest viewer count /
$name = $mydata[‘channel’][‘display_name’]; /
Store the display_name from API for user with highest viewer count /
}
}
}
}
else {
/
None of the $channels I wanted are avaiable now, so fetch the most popular one /
$backupArray = json_decode(@file_get_contents(‘https://api.twitch.tv/kraken/streams?game=league+of+legends&limit=1&offset=0’ . $callAPI), true);
if ( $backupArray != null ) {
foreach($backupArray[‘streams’] as $mydata){
if($mydata[‘_id’] != null) {
$name = $mydata[‘channel’][‘display_name’];
$viewers = $mydata[‘viewers’];
}
else {
echo “Error in results from api.twitch.tv, cannot fetch a channel.”; /
API responded but not with expected data /
}
}
}
else {
echo “Error in results from api.twitch.tv, probably cannot connect to server.”; /
API probably did not respond at all */
}
}
?>

<?php echo "$name" ?>

" bgcolor="#000000" >

I hope somebody can help me :slight_smile:
P.S. sorry for my bad english i’m from Austria

I’m guessing this has to do with your site layout and styling moreso than the PHP code that grabs the streams. Have you inspected the DOM to see what is changing whenever you click the play button?

1 Like

I recognize that code! Also, DallasNChains is right, this code would just be fetching information from the API. You need to look at the code for the player and what changes when you hit play.

Guys i solved the problem, problem was with player, tnx on your help, u can close the theme :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.