<script src= "http://player.twitch.tv/js/embed/v1.js"></script>
<div id="embed"></div>
<script type="text/javascript">
var options = {
width: 854,
height: 480,
channel: "",
};
var player = new Twitch.Player("embed", options);
var newChannel = "dj_expo"
player.setChannel(newChannel);
</script>
Hello, I’m trying to create an iframe with code, and then change the channel (that is empty by default), but the “player.setChannel” doesn’t work. And in the console, no error appears.
Hi, thanks for the reply. Sorry for my bad english
That code was just a test, and it had a mistake the http. The real problem is, as I said, the player.setChannel. I’m doing a script that updates the channel that is in the iframe, and I have a variable called actualChannel with value of = onlineUsers.data[0].user_name.
Then I show it in the console with console.log(actualChannel); and this works fine, but when in the code player.setChannel(actualChannel), the iframe keeps black and doesn’t do nothing, in console no error appears. It’s like the variable is null but no, because in the console appears the channel without any problem.
Notably how the URL’s are constructed (using a join instead of a string replace)
Your setInterval was also variable trashing… For some reason you were extracting the users ID’s and overwriting the users name array to be user_id’s instead breaking follow up calls. So I commented that section out. Not sure your intent there. You swap the names out for ID’s and then it’s all broken. Either start with ID’s or names, don’t convert mid way thru the life of the program
You also do nothing to stop the channel changing if the channel is the same and/or if more than one channel is live. It’ll change channel 5 times every 6 seconds if all 5 channels are live.
Consider something like
var live = [];
if (numberOnline > 0) {
live.push(onlineUsers.data[0].user_name);
}
if (live[0]) {
player.setChannel(live[0]);
}
Hello, the code that I uploaded last week now is working. But if it is possible, I would like the player not to be updated when the channel that is being displayed is the same, and then, updated when a new channel is placed in the “live” array above it. Thank you