Hey guys, I’m trying to embed multiple videos in my website and also hidding who gets offline.
This is the code I’m using:
<table border="1">
<colgroup>
<col class="twitch-tabela1">
<col class="twitch-tabela2">
<col class="twitch-tabela3">
</colgroup>
<!--<p>O autor do popup foi o Góes</p>-->
<!---------------------------------- Streamer 1 ---------------------------------->
<td><div id="twitch-embed1"></div>
<!-- Load the Twitch embed script -->
<script src= "https://player.twitch.tv/js/embed/v1.js"></script>
<div id="twitch1" class="hide1">
</div>
<script type="text/javascript">
var options = {
channel: "livedogoes", // TODO: Change this to the streams username you want to embed
width: 300,
height: 300,
};
var player = new Twitch.Player("twitch1", options);
player.setVolume(0.0);
player.addEventListener(Twitch.Player.READY, initiate)
function initiate() {
player.addEventListener(Twitch.Player.ONLINE, handleOnline);
player.addEventListener(Twitch.Player.OFFLINE, handleOffline);
player.removeEventListener(Twitch.Player.READY, initiate);
}
function handleOnline() {
document.getElementById("twitch1").classList.remove('hide1');
player.removeEventListener(Twitch.Player.ONLINE, handleOnline);
player.addEventListener(Twitch.Player.OFFLINE, handleOffline);
player.setMuted(true);
}
function handleOffline() {
document.getElementById("twitch1").classList.add('hide1');
player.removeEventListener(Twitch.Player.OFFLINE, handleOffline);
player.addEventListener(Twitch.Player.ONLINE, handleOnline);
player.setMuted(true);
}
</script></td>
<!---------------------------------- Streamer 2 ---------------------------------->
<td><div id="twitch-embed2"></div>
<!-- Load the Twitch embed script -->
<script src= "https://player.twitch.tv/js/embed/v1.js"></script>
<div id="twitch2" class="hide2">
</div>
<script type="text/javascript">
var options = {
channel: "gaules", // TODO: Change this to the streams username you want to embed
width: 300,
height: 300,
};
var player = new Twitch.Player("twitch2", options);
player.setVolume(0.0);
player.addEventListener(Twitch.Player.READY, initiate)
function initiate() {
player.addEventListener(Twitch.Player.ONLINE, handleOnline);
player.addEventListener(Twitch.Player.OFFLINE, handleOffline);
player.removeEventListener(Twitch.Player.READY, initiate);
}
function handleOnline() {
document.getElementById("twitch2").classList.remove('hide2');
player.removeEventListener(Twitch.Player.ONLINE, handleOnline);
player.addEventListener(Twitch.Player.OFFLINE, handleOffline);
player.setMuted(true);
}
function handleOffline() {
document.getElementById("twitch2").classList.add('hide2');
player.removeEventListener(Twitch.Player.OFFLINE, handleOffline);
player.addEventListener(Twitch.Player.ONLINE, handleOnline);
player.setMuted(true);
}
</script></td>
<!---------------------------------- Streamer 3 ---------------------------------->
<td><div id="twitch-embed3"></div>
<!-- Load the Twitch embed script -->
<script src= "https://player.twitch.tv/js/embed/v1.js"></script>
<div id="twitch3" class="hide3">
</div>
<script type="text/javascript">
var options = {
channel: "symbiolive", // TODO: Change this to the streams username you want to embed
width: 300,
height: 300,
};
var player = new Twitch.Player("twitch3", options);
player.setVolume(0.0);
player.addEventListener(Twitch.Player.READY, initiate)
function initiate() {
player.addEventListener(Twitch.Player.ONLINE, handleOnline);
player.addEventListener(Twitch.Player.OFFLINE, handleOffline);
player.removeEventListener(Twitch.Player.READY, initiate);
}
function handleOnline() {
document.getElementById("twitch3").classList.remove('hide3');
player.removeEventListener(Twitch.Player.ONLINE, handleOnline);
player.addEventListener(Twitch.Player.OFFLINE, handleOffline);
player.setMuted(true);
}
function handleOffline() {
document.getElementById("twitch3").classList.add('hide3');
player.removeEventListener(Twitch.Player.OFFLINE, handleOffline);
player.addEventListener(Twitch.Player.ONLINE, handleOnline);
player.setMuted(true);
}
</script></td>
</table>
The videos are showing normally, but when a streamer is offline is not hidding.
this is the CSS that i’m using:
<style>
.hide { display:none;
}
.twitch-imagem{
background-color: transparent;
height: 70px;
width: 110px;
cursor: pointer;
}
/* Optional: The following css just makes sure the twitch video stays responsive */
#twitch1 {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
padding-top: 25px;
height: 0;
}
#twitch2 {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
padding-top: 25px;
height: 0;
}
#twitch3 {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
padding-top: 25px;
height: 0;
}
#twitch1 object, #twitch1 iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#twitch2 object, #twitch2 iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#twitch3 object, #twitch3 iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.twitch-tabela1{
background-color: black;
height: 200px;
width: 250px;
}
.twitch-tabela2{
background-color: black;
height: 200px;
width: 250px;
}
.twitch-tabela3{
background-color: black;
height: 200px;
width: 250px;
}
</style>
Can anyone help me?
If I put only 1 streamer to show, the code works normally, if the streamer get offline, is hidding as it is supposed to do.
The code is not working only with 2+ streamers.
OBS: I already tried to use the hide1 hide2 and hide3 in the css code. Didnt work.