NAlek
![]() |
Пример middleware для цифровой ТВ-приставки D-Link DIB-120. В скрипте реализована только базовая часть функционала, позволяющая достаточно комфортно просматривать цифровое телевидение, на момент написания большего и не требовалось. Вообще, полный перечень поддерживаемых команд можно найти в интернете. Подробнее об использовании можно ознакомиться в статье IPTV Своими руками: Первый опыт mw.html <!doctype html> <html> <head> <title>IPTV</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Pragma" content="no-cache"> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="DIB120_API.js"></script> <script type="text/javascript"> <!-- var stream=new Array(); stream[0] =new Array( "udp://235.1.1.2:33033", "Planeta" ); stream[1] =new Array( "udp://235.1.1.3:33033", "TRO" ); stream[2] =new Array( "udp://235.1.1.4:33033", "InterAz" ); stream[3] =new Array( "udp://235.1.1.5:33033", "MIR" ); stream[4] =new Array( "udp://235.1.1.6:33033", "TNT" ); stream[5] =new Array( "udp://235.1.1.7:33033", "RZD" ); function Init() { InitSTB( stream, "Info", 5000, "Status", 1000 ); } window.onload = Init; window.onunload = DestroySTB; //--> </script> </head> <body> <br /> <div id="Info"></div> <div id="Status"></div> <div id="Message"></div> </body> </html> DIB120_API.js Функция processItem обрабатывает нажатие кнопок пульта. В данной реализации скрипта используются только цифровые кнопки и кнопки страничного переключения каналов (для смены каналов). Так же кнопка Play и Stop для запуска и остановки потока. Для определения идентификатора кнопки, я использовал функцию alert - при нажатии на кнопку пульта на экране отобразиться ее идентификатор. /* GLOBAL VAR */ var stb_media =new Stb_Media(); var stb =new Stb(); var webbrowser =new Webbrowser(); var device =new Device(); var _stream_array; var _stream_array_pointer; var _page_info_id; var _page_info_tmo; var _page_status_id; var _page_status_tmo; // info timer id var _id_timer_info; var _id_timer_chan; var _id_timer_status; var firstKey; var finishFirstKey; var _me_refresh_tmo =0; var _me_page_id =""; var _info_page_id =""; /* return info array 0 - serial number 1 - MAC address 2 - DRAM size 3 - CPU name 4 - CPU freq 5 - STB Model 6 - STB name 7 - display mode 8 - aspect ratio 9 - system output type 10 - system content mode */ function GetSTBInfo() { var info =new Array( device.sn, device.macaddr, device.memsize, device.cpuname, device.cpufreq, device.model, stb.deviceName, DisplayModeToString(), AspectRatioToString(), SystemOutputTypeToString(), SystemContentModeToString() ); return info; } /* initialize device */ function InitSTB( stream_array, page_info_id, page_info_tmo, page_status_id, page_status_tmo ) { stb.menutype = 2; stb.language ="en"; stb_media.setTransparentColor(0xFFFFFFFF); stb_media.setPIG(false); _stream_array =stream_array; _stream_array_pointer =0; _page_info_id =document.getElementById(page_info_id); _page_info_tmo =page_info_tmo; _page_status_id =document.getElementById(page_status_id); _page_status_tmo =page_status_tmo; _id_timer_info =-1; _id_timer_chan =-1; _id_timer_status =-1; // keypress proccess document.addEventListener( "keypress", processItem, false ); // media status ShowMediaStatus(); } function DestroySTB() { stb_media.setPIG(true,0,0,0,0); stb_media.stop(); //stb_media.setAlphaLevel(255); } // proccess keypress function processItem(event) { var key = event.keyCode ? event.keyCode : event.which; //alert(key); if(key >= 48 && key <= 58) { //readChan(key); _stream_array_pointer =key-49; PlayStream(); } else // stop & pause/play if( key >=121 && key <=122 ) { if( key ==121 ) stb_media.stop(); if( key ==122 ) { switch(stb_media.eventCode) { case 0: PlayStream(); break; //case 4: stb_media.pause(); break; //case 5: /*stb_media.continuePlay();*/updateChannel(); break; } } } else { switch(key) { // channel up case 33: if( ++_stream_array_pointer >=_stream_array.length ) _stream_array_pointer =0; PlayStream(); break; // channel down case 34: if( --_stream_array_pointer <0 ) _stream_array_pointer =_stream_array.length-1; PlayStream(); break; }// switch }// else } // play channel function PlayStream() { if( _stream_array_pointer >=0 && _stream_array_pointer <_stream_array.length) { //alert(_stream_array[_stream_array_pointer][0]); stb_media.play(_stream_array[_stream_array_pointer][0]); ShowInfoBlock( parseInt(_stream_array_pointer+1)+"<br />"+ _stream_array[_stream_array_pointer][1] ); } else ShowInfoBlock( "-" ); } // channel selector function ChannelSelector() { } // shoe winfo block function ShowInfoBlock( text ) { if( _id_timer_info !=-1 ) clearTimeout( _id_timer_info ); _page_info_id.innerHTML =text; _page_info_id.style.display = "block"; _id_timer_info =setTimeout("_page_info_id.style.display = 'none';", _page_info_tmo); } // show status function ShowMediaStatus() { if( _id_timer_status !=-1 ) clearTimeout( _id_timer_status ); var a; switch(stb_media.eventCode) { case 0: a ="Остановлено"; break; case 1: a ="Ошибка"; break; case 2: a ="EOF"; break; case 3: a ="Буферизация..."; break; case 4: a ="Воспроизведение..."; break; case 5: a ="Пауза"; break; case 6: a ="Остановка..."; break; default: a ="?"; } if( _page_status_id ) { if( stb_media.eventCode ==4 ) _page_status_id.style.display = "none"; else _page_status_id.style.display = "block"; _page_status_id.innerHTML =a; } if( _page_status_tmo ) _id_timer_status =setTimeout( "ShowMediaStatus()", _page_status_tmo ); } /* change stb name */ function SetSTBName( name ) { stb.deviceName =name; } /* set display mode 0 - NTSC 1 - NTSC-JAPAN 2 - PAL-M 3 - PAL-N 4 - PAL-NC 5 - PAL-B 6 - PAL-B1 7 - PAL-D 8 - PAL-D1 9 - PAL 10 - PAL-H 11 - PAL-K 12 - PAL-I 13 - SECAM 14 - 480P 15 - 576P 16 - 1080I 17 - 1080I-50HZ 18 - 1080P 19 - 1080P-24HZ 20 - 1080P-25HZ 21 - 1080P-30HZ 22 - 1250I-50HZ 23 - 720P 24 - 720P-50HZ 25 - 720P-24HZ */ function SetDisplayMode( up ) { if( up ) { if( stb.displaymode >=25 ) stb.displaymode =0; else stb.displaymode =stb.displaymode+1; } else { if( stb.displaymode <=0 ) stb.displaymode =25; else stb.displaymode =stb.displaymode-1; } return DisplayModeToString(); } // displaymode to string function DisplayModeToString() { // dispaly mode to string switch( stb.displaymode ) { case 0: displaymode ="NTSC"; break; case 1: displaymode ="NTSC-JAPAN"; break case 2: displaymode ="PAL-M"; break; case 3: displaymode ="PAL-N"; break; case 4: displaymode ="PAL-NC"; break; case 5: displaymode ="PAL-B"; break; case 6: displaymode ="PAL-B1"; break; case 7: displaymode ="PAL-D"; break; case 8: displaymode ="PAL-D1"; break; case 9: displaymode ="PAL"; break; case 10: displaymode ="PAL-H"; break; case 11: displaymode ="PAL-K"; break; case 12: displaymode ="PAL-I"; break; case 13: displaymode ="SECAM"; break; case 14: displaymode ="480P"; break; case 15: displaymode ="576P"; break; case 16: displaymode ="1080I"; break; case 17: displaymode ="1080I-50HZ"; break; case 18: displaymode ="1080P"; break; case 19: displaymode ="1080P-24HZ"; break; case 20: displaymode ="1080P-25HZ"; break; case 21: displaymode ="1080P-30HZ"; break; case 22: displaymode ="1250I-50HZ"; break; case 23: displaymode ="720P"; break; case 24: displaymode ="720P-50HZ"; break; case 25: displaymode ="720P-24HZ"; break; }// switch return displaymode; } /* change aspect ratio 0 - 4:3 1 - 16:9 */ function SetAspectRatio( up ) { // switch to up if( up ) { if( stb.aspect >=1 ) stb.aspect =0; else stb.aspect =stb.aspect+1; } // switch to dowm else { if( stb.aspect <=0 ) stb.aspect =1; else stb.aspect =stb.aspect-1; } return AspectRatioToString(); } // aspect ratio to string function AspectRatioToString() { switch(stb.aspect) { case 0: aspect ="4:3"; case 1: aspect ="16:9"; } return aspect; } /* change output type 0 - RGB(Component) 1 - YPbPr(YcbCr) */ function SetSystemOutputType( up ) { // switch to up if( up ) { if( stb.outputtype >=1 ) stb.outputtype =0; else stb.outputtype =stb.outputtype+1; } // switch to down else { if( stb.outputtype <=0 ) stb.outputtype =1; else stb.outputtype =stb.outputtype-1; } return SystemOutputTypeToString(); } // output type to string function SystemOutputTypeToString() { switch(stb.outputtype) { case 0: outputtype="RGB(Component)"; case 1: outputtype="YPbPr(YcbCr)"; } return outputtype; } /* change system content mode 0 - Zoom 1 - Box 2 - PanScan 3 - Full 4 - Full-NonLiner */ function SetSystemContentMode( up ) { // switch to up if( up ) { if( stb.content >=4 ) stb.content =0; else stb.content =stb.content+1; } // switch to down else { if( stb.content <=0 ) stb.content =4; else stb.content =stb.content-1; } return SystemContentModeToString(); } // content mode to string function SystemContentModeToString() { // system content mode to string switch(stb.content) { case 0: content ="Zoom"; break; case 1: content ="Box"; break; case 2: content ="PanScan"; break; case 3: content ="Full"; break; case 4: content ="Full-NonLiner"; break; }// switch return content; } /* !!!!!! CALL IT */ function SaveOSD() { return stb.save_osd(); } style.css * { margin:10px; padding:10px; } body { font-family: Verdana, Tahoma, arial, geneva, Helvetica, sans-serif; font-size: 17px; color: #000000; background-color: #ffffff; } #Info { display: none; float: left; background-color: #0080FF; width: 50px; } #Status { display: none; /*clear: both;*/ /*background-color: #0080FF;*/ color: red; font-size: 30px; } #Message { display: none; clear: both; /*background-color: #0080FF;*/ color: red; font-size: 30px; } ![]() |