Difference between revisions of "External Playlist"

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 fo…»)
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
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.
+
Если вы хотите показывать плейлист на странице, вы можете использовать внешний плейлист (плейлист, который можно разместить в любом месте на странице, используя стандартный html). Удобно для быстрого переключения между каналами, например.
  
You can see an example of external playlist here: http://torrentstream.org/test/test_playlist.html
+
Пример внешнего плейлиста вы можете посмотреть здесь: http://torrentstream.org/test/test_playlist.html
  
First, you need to load our javascript library:
+
Сначала вам необходимо загрузить нашу библиотеку javascript:
 
  <tt><script type="text/javascript" src="http://static.torrentstream.org/jsapi/js/lib/ts/core.js"></script>
 
  <tt><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></tt>
 
  <script type="text/javascript" src="http://static.torrentstream.org/jsapi/js/lib/ts/player.js"></script></tt>
  
We update javascript library frequenly, so we recommend to load javascript files from our servers, not to store them on your servers.
+
Мы периодически обновляем библиотеку javascript, поэтому рекомендуем загружать javascript файлы с наших серверов, а не хранить их на ваших серверах.
  
Then you need to create the player object:
+
Затем вам необходимо создать плеер:
 
  <tt>player = new TorrentStream.Player(document.getElementById("player"), {
 
  <tt>player = new TorrentStream.Player(document.getElementById("player"), {
 
         useInternalControls: true,
 
         useInternalControls: true,
Line 20: Line 20:
 
         }
 
         }
 
  });</tt>
 
  });</tt>
Player object constructor takes two parameters: <tt>TorrentStream.Player(container, config)</tt>
+
Конструктор плеера принимает два параметра: <tt>TorrentStream.Player(container, config)</tt>
*''container'' - html element, which will be used as player container
+
*''container'' - html элемент, который будет использован как контейнер плеера
*''config'' - an object with optional configuration params
+
*''config'' - объект с дополнительными параметрами конфигурации
  
In this example we use such options:
+
В данном примере мы используем следующие опции:
*''useInternalControls'': show controls inside plugin's window
+
*''useInternalControls'': показывать панель управления внутри окна плагина
*''onLoad'': this function is called when the plugin has finished loading and is ready for usage
+
*''onLoad'': эта функция вызывается, когда плагин закончил загрузку и готов к использованию
  
In the ''onLoad'' callback we load five channels in the playlist, using player's method loadTorrent.
+
При возврате ''onLoad'' мы загружаем пять каналов в плейлист, используя метод плеера 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:
+
Если плагин не установлен, выбрасывается исключение "plugin_not_installed". Вы можете перехватить это исключение и показать какое-нибудь сообщение пользователю. Например, так:
 
  <tt>try {
 
  <tt>try {
 
     player = new TorrentStream.Player(...);
 
     player = new TorrentStream.Player(...);
Line 36: Line 36:
 
  catch(e) {
 
  catch(e) {
 
     if(e == "plugin_not_installed") {
 
     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>";
+
         document.getElementById("message").innerHTML = "Плагин не установлен. Установить <a href=\"http://dl.torrentstream.org/products/torrentstream-full/win/latest\" target=\"_blank\">здесь</a>";
 
     }
 
     }
 
     else {
 
     else {
Line 43: Line 43:
 
  }</tt>
 
  }</tt>
  
Then create an external playlist:
+
Затем создайте внешний плеер:
 
  <nowiki><div class="playlist-item" onclick="playChannel(0);">ТНТ</div>
 
  <nowiki><div class="playlist-item" onclick="playChannel(0);">ТНТ</div>
 
<div class="playlist-item" onclick="playChannel(1);">Первый канал</div>
 
<div class="playlist-item" onclick="playChannel(1);">Первый канал</div>
Line 50: Line 50:
 
<div class="playlist-item" onclick="playChannel(4);">СТС</div></nowiki>
 
<div class="playlist-item" onclick="playChannel(4);">СТС</div></nowiki>
  
Clicking on playlist items is handled by function playChannel():
+
Нажатие на пунктах плейлиста производится функцией playChannel():
 
  <tt>function playChannel(playlistIndex) {
 
  <tt>function playChannel(playlistIndex) {
 
     if(!player) {
 
     if(!player) {
Line 59: Line 59:
 
  }</tt>
 
  }</tt>
  
This functions checks whether the player object exists and then call play() method which takes zero-based playlist item index as first argument.
+
Эта функция проверяет, существует ли плеер, а потом вызывает метод play(), который принимает первый пункт плейлиста как первый аргумент.

Latest revision as of 11:48, 24 December 2012

Если вы хотите показывать плейлист на странице, вы можете использовать внешний плейлист (плейлист, который можно разместить в любом месте на странице, используя стандартный html). Удобно для быстрого переключения между каналами, например.

Пример внешнего плейлиста вы можете посмотреть здесь: http://torrentstream.org/test/test_playlist.html

Сначала вам необходимо загрузить нашу библиотеку javascript:

<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>

Мы периодически обновляем библиотеку javascript, поэтому рекомендуем загружать javascript файлы с наших серверов, а не хранить их на ваших серверах.

Затем вам необходимо создать плеер:

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});
        }
});

Конструктор плеера принимает два параметра: TorrentStream.Player(container, config)

  • container - html элемент, который будет использован как контейнер плеера
  • config - объект с дополнительными параметрами конфигурации

В данном примере мы используем следующие опции:

  • useInternalControls: показывать панель управления внутри окна плагина
  • onLoad: эта функция вызывается, когда плагин закончил загрузку и готов к использованию

При возврате onLoad мы загружаем пять каналов в плейлист, используя метод плеера loadTorrent.

Если плагин не установлен, выбрасывается исключение "plugin_not_installed". Вы можете перехватить это исключение и показать какое-нибудь сообщение пользователю. Например, так:

try {
    player = new TorrentStream.Player(...);
}
catch(e) {
    if(e == "plugin_not_installed") {
        document.getElementById("message").innerHTML = "Плагин не установлен. Установить <a href=\"http://dl.torrentstream.org/products/torrentstream-full/win/latest\" target=\"_blank\">здесь</a>";
    }
    else {
        alert(e);
    }
}

Затем создайте внешний плеер:

<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>

Нажатие на пунктах плейлиста производится функцией playChannel():

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

Эта функция проверяет, существует ли плеер, а потом вызывает метод play(), который принимает первый пункт плейлиста как первый аргумент.