External Playlist/en

From Ace Stream Wiki
Jump to: navigation, search

If you want to show the playlist on the page you can use external playlist (a playlist which can be placed anywhere on the page using standart html). It is useful for fast switching between channels, for example.

You can see an example of external playlist here: http://torrentstream.org/test/test_playlist.html

First, you need to load our javascript library:

<script type="text/javascript" src="http://static.torrentstream.org/jsapi/js/lib/ts/core.js"></script>
<script type="text/javascript" src="http://static.torrentstream.org/jsapi/js/lib/ts/player.js"></script>

We update javascript library frequenly, so we recommend to load javascript files from our servers, not to store them on your servers.

Then you need to create the player object:

player = new TorrentStream.Player(document.getElementById("player"), {
        useInternalControls: true,
        onLoad: function() {
            this.loadTorrent("", {async: false});
            this.loadTorrent("", {async: false});
            this.loadTorrent("", {async: false});
            this.loadTorrent("", {async: false});
            this.loadTorrent("", {async: false});

Player object constructor takes two parameters: TorrentStream.Player(container, config)

  • container - html element, which will be used as player container
  • config - an object with optional configuration params

In this example we use such options:

  • useInternalControls: show controls inside plugin's window
  • onLoad: this function is called when the plugin has finished loading and is ready for usage

In the onLoad callback we load five channels in the playlist, using player's method loadTorrent.

If the plugin is not installed an exception "plugin_not_installed" is thrown. You can catch this exception and show some message to the user, for example, this way:

try {
    player = new TorrentStream.Player(...);
catch(e) {
    if(e == "plugin_not_installed") {
        document.getElementById("message").innerHTML = "Plugin not installed. Install <a href=\"http://dl.torrentstream.org/products/torrentstream-full/win/latest\" target=\"_blank\">here</a>";
    else {

Then create an external playlist:

<div class="playlist-item" onclick="playChannel(0);">ТНТ</div>
<div class="playlist-item" onclick="playChannel(1);">Первый канал</div>
<div class="playlist-item" onclick="playChannel(2);">Discovery Channel</div>
<div class="playlist-item" onclick="playChannel(3);">Спорт 1</div>
<div class="playlist-item" onclick="playChannel(4);">СТС</div>

Clicking on playlist items is handled by function playChannel():

function playChannel(playlistIndex) {
    if(!player) {
        alert("Player is not loaded");

This functions checks whether the player object exists and then call play() method which takes zero-based playlist item index as first argument.