Skip to content

Latest commit

 

History

History
185 lines (175 loc) · 5.09 KB

player.md

File metadata and controls

185 lines (175 loc) · 5.09 KB

Twitch Player API

We expose a JavaScript API for our Flash Twitch player that gives flexibility and functionality to embedding. The IFrame embed does not yet have an external interface.

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 = $("#twitch_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
isPaused Gets the playing status of the video. Returns boolean true or false
loadStream Loads a given stream. Parameter is a channel name (as a String).
loadVideo Loads a given video. Parameter is the video ID (as a String).
mute Mutes the player.
onlineStatus Returns the online status of the loaded stream. Values returned are online, offline, or unknown.
pauseVideo If stream is online, will pause the player.
playVideo If stream is online, will play the player.
videoSeek Seeks a video. Parameter is seconds (as a Number)
unmute Unmutes the player.

Events

Events are emitted through the eventsCallback Flash player parameter in the following form:

[
  {
    "event": "",
    "data": {}
  },
  ...
]
Event Description Data
streamLoaded Emitted when a stream is loaded in the video player
{
  channel: "test_stream",
  channelSteamId: null,
  videoId: null,
  videoLengthInSecs: 0,
  viewerSteamId: null
}
videoLoaded Emitted when a video is loaded in the video player
{
  channel: "test_stream",
  channelSteamId: null,
  videoId: "4345634",
  videoLengthInSecs: 15,
  viewerSteamId: null
}
online Emitted when the stream is online (emitted on stream load too)
{}
offline Emitted when the stream goes offline
{}
viewerCount The viewer count is emitted periodically for streams
{
  channel: "test_stream",
  viewers: 12975
}
videoLoading Emitted when a stream or video is loading
{}
playerInit Emitted when the player is loaded
{}
videoPlaying Emitted when a stream or video starts playing
{}
mouseScroll Emitted when the user scrolls over the video
{
  delta: 1
}