Open main menu

Ace Stream Wiki β

External Playlist

Revision as of 20:51, 11 December 2012 by Anton (talk | contribs) (Новая страница: «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 fo…»)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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("http://94.242.221.195:7773/file?name=%D0%A2%D0%9D%D0%A2", {async: false});
            this.loadTorrent("http://94.242.221.195:7764/file?name=%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B9+%D0%BA%D0%B0%D0%BD%D0%B0%D0%BB", {async: false});
            this.loadTorrent("http://94.242.221.195:7802/file?name=Discovery+Channel", {async: false});
            this.loadTorrent("http://94.242.221.195:7771/file?name=%D0%A1%D0%BF%D0%BE%D1%80%D1%82+1", {async: false});
            this.loadTorrent("http://94.242.221.195:7805/file?name=%D0%A1%D0%A2%D0%A1", {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 {
        alert(e);
    }
}

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");
        return;
    }
    player.play(playlistIndex);
}

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