Broccoli
Broccoli

Reputation: 83

Twitch related: Twitch Video player

I am having a problem with twitch video player.

When I add the video player to the website and define the username without a PHP var it loads like it should but as soon as I add a var from PHP it doesn't load the stream from twitch.

This is how the code looks like with out the php Var (JS):

<script src= "http://player.twitch.tv/js/embed/v2.js"></script>
<div id="{PLAYER_DIV_ID}"></div>
<script type="text/javascript">
    var options = {
        width: '100%',
        height: 480,
        channel: "channel", 
        //video: "{VIDEO_ID}"       
    };
    var player = new Twitch.Player("{PLAYER_DIV_ID}", options);
    player.setVolume(0.3);
</script>

This is the code with the PHP var (the one that won't work.

<script src= "http://player.twitch.tv/js/embed/v2.js"></script>
<div id="{PLAYER_DIV_ID}"></div>
<script type="text/javascript">
    var options = {
        width: '100%',
        height: 480,
        channel: "<?php $channel ?>", 
        //video: "{VIDEO_ID}"       
    };
    var player = new Twitch.Player("{PLAYER_DIV_ID}", options);
    player.setVolume(0.3);
</script>

There might be a stupid questions. This is the first time I add "PHP" to a "JS" script like this, so I might do something wrong.

Upvotes: 0

Views: 982

Answers (1)

naortor
naortor

Reputation: 2089

There is a problem with your php code -

You should do

<?php echo $channel?>

OR just

<?= $channel ?>

Upvotes: 2

Related Questions