Skip to content

Latest commit

 

History

History
81 lines (74 loc) · 2.41 KB

player.md

File metadata and controls

81 lines (74 loc) · 2.41 KB

Twitch Player API

We expose a Javascript API for our flash Twitch player that gives flexibility and functionality to embedding.

Example code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>
      $(function () {
        window.onPlayerEvent = function (data) {
          data.forEach(function(event) {
            if (event.event == "playerInit") {
              var player = $("#live_embed_player")[0];
              player.playVideo();
              player.mute();
            }
        });
        
        swfobject.embedSWF("//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf", "twitch_embed_player", "640", "400", "11", null,
          { "eventsCallback":"onPlayerEvent",
            "embed":1,
            "channel":"day9tv",
            "auto_play":"true"},
          { "allowScriptAccess":"always",
            "allowFullScreen":"true"});
      });
    </script>
  </head>
  <body>
    <div id="twitch_embed_player">
    </div>
  </body>
</html>

Functions

Name Description
playVideo If stream is online, will play the player.
pauseVideo If stream is online, will pause the player.
mute Mutes the player.
unmute Unmutes the player.
onlineStatus Returns the online status of the loaded stream. Values are online, offline, or unknown.
loadStream Loads a given stream. Parameter is a string.
loadVideo Loads a given video. Parameter is the video id.