1 /*****************************************************************************
2 * functions.js: VLC media player web interface
3 *****************************************************************************
4 * Copyright (C) 2005-2006 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /**********************************************************************
26 *********************************************************************/
33 /**********************************************************************
35 *********************************************************************/
37 var slider_mouse_down = 0;
40 /* findPosX() from http://www.quirksmode.rg/js/indpos.html */
41 function findPosX(obj)
46 while (obj.offsetParent)
48 curleft += obj.offsetLeft
49 obj = obj.offsetParent;
57 function slider_seek( e, bar )
59 seek(Math.floor(( e.clientX + document.body.scrollLeft - findPosX( bar )) / 4)+"%25");
61 function slider_down( e, point )
63 slider_mouse_down = 1;
64 slider_dx = e.clientX - findPosX( point );
66 function slider_up( e, bar )
68 slider_mouse_down = 0;
69 /* slider_seek( e, bar ); */
71 function slider_move( e, bar )
73 if( slider_mouse_down == 1 )
75 var slider_position = Math.floor( e.clientX - slider_dx + document.body.scrollLeft - findPosX( bar ));
76 document.getElementById( 'main_slider_point' ).style.left = slider_position+"px";
77 slider_seek( e, bar );
81 /**********************************************************************
83 *********************************************************************/
85 /* XMLHttpRequest wrapper */
86 function loadXMLDoc( url, callback )
88 // branch for native XMLHttpRequest object
89 if ( window.XMLHttpRequest )
91 req = new XMLHttpRequest();
92 req.onreadystatechange = callback;
93 req.open( "GET", url, true );
95 // branch for IE/Windows ActiveX version
97 else if ( window.ActiveXObject )
99 req = new ActiveXObject( "Microsoft.XMLHTTP" );
102 req.onreadystatechange = callback;
103 req.open( "GET", url, true );
109 /* fomat time in second as hh:mm:ss */
110 function format_time( s )
112 var hours = Math.floor(s/3600);
113 var minutes = Math.floor((s/60)%60);
114 var seconds = Math.floor(s%60);
115 if( hours < 10 ) hours = "0"+hours;
116 if( minutes < 10 ) minutes = "0"+minutes;
117 if( seconds < 10 ) seconds = "0"+seconds;
118 return hours+":"+minutes+":"+seconds;
121 /* delete all a tag's children and add a text child node */
122 function set_text( id, val )
124 var elt = document.getElementById( id );
125 while( elt.hasChildNodes() )
126 elt.removeChild( elt.firstChild );
127 elt.appendChild( document.createTextNode( val ) );
130 /* set item's 'element' attribute to value */
131 function set_css( item, element, value )
133 for( var j = 0; j < document.styleSheets.length; j++ )
135 var cssRules = document.styleSheets[j].cssRules;
136 if( !cssRules ) cssRules = document.styleSheets[j].rules;
137 for( var i = 0; i < cssRules.length; i++)
139 if( cssRules[i].selectorText == item )
141 if( cssRules[i].style.setProperty )
142 cssRules[i].style.setProperty( element, value, null );
144 cssRules[i].style.setAttribute( toCamelCase( element ), value );
151 /* get item's 'element' attribute */
152 function get_css( item, element )
154 for( var j = 0; j < document.styleSheets.length; j++ )
156 var cssRules = document.styleSheets[j].cssRules;
157 if( !cssRules ) cssRules = document.styleSheets[j].rules;
158 for( var i = 0; i < cssRules.length; i++)
160 if( cssRules[i].selectorText == item )
162 if( cssRules[i].style.getPropertyValue )
163 return cssRules[i].style.getPropertyValue( element );
165 return cssRules[i].style.getAttribute( toCamelCase( element ) );
171 function toggle_show( id )
173 var element = document.getElementById( id );
174 if( element.style.display == 'block' || element.style.display == '' )
176 element.style.display = 'none';
180 element.style.display = 'block';
183 function toggle_show_node( id )
185 var element = document.getElementById( 'pl_'+id );
186 var img = document.getElementById( 'pl_img_'+id );
187 if( element.style.display == 'block' || element.style.display == '' )
189 element.style.display = 'none';
190 img.setAttribute( 'src', 'images/plus.png' );
191 img.setAttribute( 'alt', '[+]' );
195 element.style.display = 'block';
196 img.setAttribute( 'src', 'images/minus.png' );
197 img.setAttribute( 'alt', '[-]' );
201 function show( id ){ document.getElementById( id ).style.display = 'block'; }
202 function showinline( id ){ document.getElementById( id ).style.display = 'inline'; }
204 function hide( id ){ document.getElementById( id ).style.display = 'none'; }
206 function checked( id ){ return document.getElementById( id ).checked; }
208 function value( id ){ return document.getElementById( id ).value; }
210 function setclass( obj, value )
212 obj.setAttribute( 'class', value ); /* Firefox */
213 obj.setAttribute( 'className', value ); /* IE */
216 function radio_value( name )
218 var radio = document.getElementsByName( name );
219 for( var i = 0; i < radio.length; i++ )
221 if( radio[i].checked )
223 return radio[i].value;
229 function check_and_replace_int( id, val )
231 var objRegExp = /^\d+$/;
232 if( value( id ) != ''
233 && ( !objRegExp.test( value( id ) )
234 || parseInt( value( id ) ) < 1 ) )
235 return document.getElementById( id ).value = val;
236 return document.getElementById( id ).value;
239 function addslashes( str ){ return str.replace(/\'/g, '\\\''); }
240 function escapebackslashes( str ){ return str.replace(/\\/g, '\\\\'); }
242 function toCamelCase( str )
244 str = str.split( '-' );
246 for( var i=1; i<str.length; i++)
247 cml += str[i].charAt(0).toUpperCase()+str[i].substring(1);
251 function disable( id ){ document.getElementById( id ).disabled = true; }
253 function enable( id ){ document.getElementById( id ).disabled = false; }
255 function button_over( element ){ element.style.border = "1px solid #000"; }
257 function button_out( element ){ element.style.border = "1px solid #fff"; }
258 function button_out_menu( element ){ element.style.border = "1px solid transparent"; }
260 function show_menu( id ){ document.getElementById(id).style.display = 'block'; }
261 function hide_menu( id ){ document.getElementById(id).style.display = 'none'; }
263 /* toggle show help under the buttons */
264 function toggle_btn_text()
266 if( get_css( '.btn_text', 'display' ) == 'none' )
268 set_css( '.btn_text', 'display', 'block' );
272 set_css( '.btn_text', 'display', 'none' );
276 function clear_children( elt )
279 while( elt.hasChildNodes() )
280 elt.removeChild( elt.firstChild );
283 /**********************************************************************
285 *********************************************************************/
289 var input = value('input_mrl');
290 if( value('sout_mrl') != '' )
291 input += ' '+value('sout_mrl');
292 var url = 'requests/status.xml?command=in_play&input='+encodeURIComponent( addslashes(escapebackslashes(input)) );
293 loadXMLDoc( url, parse_status );
294 setTimeout( 'update_playlist()', 1000 );
296 function in_enqueue()
298 var input = value('input_mrl');
299 if( value('sout_mrl') != '' )
300 input += ' '+value('sout_mrl');
301 var url = 'requests/status.xml?command=in_enqueue&input='+encodeURIComponent( addslashes(escapebackslashes(input)) );
302 loadXMLDoc( url, parse_status );
303 setTimeout( 'update_playlist()', 1000 );
306 /* playlist actions */
307 function pl_play( id )
309 loadXMLDoc( 'requests/status.xml?command=pl_play&id='+id, parse_status );
311 setTimeout( 'update_playlist()', 1000 );
315 loadXMLDoc( 'requests/status.xml?command=pl_pause&id='+pl_cur_id, parse_status );
319 loadXMLDoc( 'requests/status.xml?command=pl_stop', parse_status );
320 setTimeout( 'update_playlist()', 1000 );
324 loadXMLDoc( 'requests/status.xml?command=pl_next', parse_status );
325 setTimeout( 'update_playlist()', 1000 );
327 function pl_previous()
329 loadXMLDoc( 'requests/status.xml?command=pl_previous', parse_status );
330 setTimeout( 'update_playlist()', 1000 );
332 function pl_delete( id )
334 loadXMLDoc( 'requests/status.xml?command=pl_delete&id='+id, parse_status );
335 setTimeout( 'update_playlist()', 1000 );
339 loadXMLDoc( 'requests/status.xml?command=pl_empty', parse_status );
340 setTimeout( 'update_playlist()', 1000 );
342 function pl_sort( sort, order )
344 loadXMLDoc( 'requests/status.xml?command=pl_sort&id='+order+'&val='+sort, parse_status );
345 setTimeout( 'update_playlist()', 1000 );
347 function pl_shuffle()
349 loadXMLDoc( 'requests/status.xml?command=pl_random', parse_status );
350 setTimeout( 'update_playlist()', 1000 );
354 loadXMLDoc( 'requests/status.xml?command=pl_loop', parse_status );
358 loadXMLDoc( 'requests/status.xml?command=pl_repeat', parse_status );
360 function pl_sd( value )
362 loadXMLDoc( 'requests/status.xml?command=pl_sd&val='+value, parse_status );
366 function volume_down()
368 loadXMLDoc( 'requests/status.xml?command=volume&val=-20', parse_status );
372 loadXMLDoc( 'requests/status.xml?command=volume&val=%2B20', parse_status );
376 loadXMLDoc( 'requests/status.xml?command=seek&val='+pos, parse_status );
378 function fullscreen()
380 loadXMLDoc( 'requests/status.xml?command=fullscreen', parse_status );
384 loadXMLDoc( 'requests/status.xml?command=snapshot', parse_status );
386 function hotkey( str )
388 /* Use hotkey name (without the "key-" part) as the argument to simulate a hotkey press */
389 loadXMLDoc( 'requests/status.xml?command=key&val='+str, parse_status );
391 function update_status()
393 if( req == null || req.readyState == 0 || req.readyState == 4 )
395 loadXMLDoc( 'requests/status.xml', parse_status );
398 function update_playlist()
400 loadXMLDoc( 'requests/playlist.xml', parse_playlist );
403 /**********************************************************************
404 * Parse xml replies to XMLHttpRequests
405 *********************************************************************/
406 /* parse request/status.xml */
407 function parse_status()
409 if( req.readyState == 4 )
411 if( req.status == 200 )
413 var status = req.responseXML.documentElement;
414 var timetag = status.getElementsByTagName( 'time' );
415 if( timetag.length > 0 )
417 var new_time = timetag[0].firstChild.data;
423 var lengthtag = status.getElementsByTagName( 'length' );
425 if( lengthtag.length > 0 )
427 length = lengthtag[0].firstChild.data;
434 positiontag = status.getElementsByTagName( 'position' );
435 if( length < 100 && positiontag.length > 0 )
437 slider_position = ( positiontag[0].firstChild.data * 4 ) + "px";
439 else if( length > 0 )
441 /* this is more precise if length > 100 */
442 slider_position = Math.floor( ( new_time * 400 ) / length ) + "px";
448 if( old_time > new_time )
449 setTimeout('update_playlist()',50);
451 set_text( 'time', format_time( new_time ) );
452 set_text( 'length', format_time( length ) );
453 if( status.getElementsByTagName( 'volume' ).length != 0 )
454 set_text( 'volume', Math.floor(status.getElementsByTagName( 'volume' )[0].firstChild.data/5.12)+'%' );
455 var statetag = status.getElementsByTagName( 'state' );
456 if( statetag.length > 0 )
458 set_text( 'state', statetag[0].firstChild.data );
462 set_text( 'state', '(?)' );
464 if( slider_mouse_down == 0 )
466 document.getElementById( 'main_slider_point' ).style.left = slider_position;
468 var statustag = status.getElementsByTagName( 'state' );
469 if( statustag.length > 0 ? statustag[0].firstChild.data == "playing" : 0 )
471 document.getElementById( 'btn_pause_img' ).setAttribute( 'src', 'images/pause.png' );
472 document.getElementById( 'btn_pause_img' ).setAttribute( 'alt', 'Pause' );
473 document.getElementById( 'btn_pause' ).setAttribute( 'title', 'Pause' );
477 document.getElementById( 'btn_pause_img' ).setAttribute( 'src', 'images/play.png' );
478 document.getElementById( 'btn_pause_img' ).setAttribute( 'alt', 'Play' );
479 document.getElementById( 'btn_pause' ).setAttribute( 'title', 'Play' );
482 var randomtag = status.getElementsByTagName( 'random' );
483 if( randomtag.length > 0 ? randomtag[0].firstChild.data == "1" : 0)
484 setclass( document.getElementById( 'btn_shuffle'), 'on' );
486 setclass( document.getElementById( 'btn_shuffle'), 'off' );
488 var looptag = status.getElementsByTagName( 'loop' );
489 if( looptag.length > 0 ? looptag[0].firstChild.data == "1" : 0)
490 setclass( document.getElementById( 'btn_loop'), 'on' );
492 setclass( document.getElementById( 'btn_loop'), 'off' );
494 var repeattag = status.getElementsByTagName( 'repeat' );
495 if( repeattag.length > 0 ? repeattag[0].firstChild.data == "1" : 0 )
496 setclass( document.getElementById( 'btn_repeat'), 'on' );
498 setclass( document.getElementById( 'btn_repeat'), 'off' );
500 var tree = document.createElement( "ul" );
501 var categories = status.getElementsByTagName( 'category' );
503 for( i = 0; i < categories.length; i++ )
505 var item = document.createElement( "li" );
506 item.appendChild( document.createTextNode( categories[i].getAttribute( 'name' ) ) );
507 var subtree = document.createElement( "dl" );
508 var infos = categories[i].getElementsByTagName( 'info' );
510 for( j = 0; j < infos.length; j++ )
512 var subitem = document.createElement( "dt" );
513 subitem.appendChild( document.createTextNode( infos[j].getAttribute( 'name' ) ) );
514 subtree.appendChild( subitem );
515 if( infos[j].hasChildNodes() )
517 var subitem = document.createElement( "dd" );
518 subitem.appendChild( document.createTextNode( infos[j].firstChild.data ) );
519 subtree.appendChild( subitem );
522 item.appendChild( subtree );
523 tree.appendChild( item );
525 var infotree = document.getElementById('infotree' );
526 clear_children( infotree );
527 infotree.appendChild( tree );
532 /*alert( 'Error! HTTP server replied: ' + req.status );*/
537 /* parse playlist.xml */
538 function parse_playlist()
540 if( req.readyState == 4 )
542 if( req.status == 200 )
544 var answer = req.responseXML.documentElement;
545 var playtree = document.getElementById( 'playtree' );
546 var pos = document.createElement( "div" );
547 pos.style.height = document.body.clientHeight - 100 + "px";
548 pos.style.overflow = "auto";
550 var elt = answer.firstChild;
552 pl_cur_id = 0; /* changed to the current id is there actually
556 if( elt.nodeName == "node" )
558 if( pos.hasChildNodes() )
559 pos.appendChild( document.createElement( "br" ) );
560 var nda = document.createElement( 'a' );
561 nda.setAttribute( 'href', 'javascript:toggle_show_node(\''+elt.getAttribute( 'id' )+'\');' );
562 var ndai = document.createElement( 'img' );
563 ndai.setAttribute( 'src', 'images/minus.png' );
564 ndai.setAttribute( 'alt', '[-]' );
565 ndai.setAttribute( 'id', 'pl_img_'+elt.getAttribute( 'id' ) );
566 nda.appendChild( ndai );
567 pos.appendChild( nda );
568 pos.appendChild( document.createTextNode( ' ' + elt.getAttribute( 'name' ) ) );
570 if( elt.getAttribute( 'ro' ) == 'rw' )
572 pos.appendChild( document.createTextNode( ' ' ) );
573 var del = document.createElement( "a" );
574 del.setAttribute( 'href', 'javascript:pl_delete('+elt.getAttribute( 'id' )+')' );
575 var delimg = document.createElement( "img" );
576 delimg.setAttribute( 'src', 'images/delete_small.png' );
577 delimg.setAttribute( 'alt', '(delete)' );
578 del.appendChild( delimg );
579 pos.appendChild( del );
582 var nd = document.createElement( "div" );
583 setclass( nd, 'pl_node' );
584 nd.setAttribute( 'id', 'pl_'+elt.getAttribute( 'id' ) );
585 pos.appendChild( nd );
587 else if( elt.nodeName == "leaf" )
589 if( pos.hasChildNodes() )
590 pos.appendChild( document.createElement( "br" ) );
591 var pl = document.createElement( "a" );
592 setclass( pl, 'pl_leaf' );
593 pl.setAttribute( 'href', 'javascript:pl_play('+elt.getAttribute( 'id' )+');' );
594 pl.setAttribute( 'id', 'pl_'+elt.getAttribute( 'id' ) );
595 if( elt.getAttribute( 'current' ) == 'current' )
597 pl.style.fontWeight = 'bold';
598 var nowplaying = document.getElementById( 'nowplaying' );
599 clear_children( nowplaying );
600 nowplaying.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
601 pl.appendChild( document.createTextNode( '* '));
602 pl_cur_id = elt.getAttribute( 'id' );
604 pl.setAttribute( 'title', elt.getAttribute( 'uri' ));
605 pl.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
606 var duration = elt.getAttribute( 'duration' );
608 pl.appendChild( document.createTextNode( " (" + format_time( elt.getAttribute( 'duration' ) / 1000000 ) + ")" ) );
609 pos.appendChild( pl );
611 if( elt.getAttribute( 'ro' ) == 'rw' )
613 pos.appendChild( document.createTextNode( ' ' ) );
614 var del = document.createElement( "a" );
615 del.setAttribute( 'href', 'javascript:pl_delete('+elt.getAttribute( 'id' )+')' );
616 var delimg = document.createElement( "img" );
617 delimg.setAttribute( 'src', 'images/delete_small.png' );
618 delimg.setAttribute( 'alt', '(delete)' );
619 del.appendChild( delimg );
620 pos.appendChild( del );
625 elt = elt.firstChild;
628 else if( elt.nextSibling )
630 elt = elt.nextSibling;
635 while( ! elt.parentNode.nextSibling )
637 elt = elt.parentNode;
638 if( ! elt.parentNode ) break;
639 pos = pos.parentNode;
641 if( ! elt.parentNode ) break;
642 elt = elt.parentNode.nextSibling;
643 pos = pos.parentNode;
646 clear_children( playtree );
647 playtree.appendChild( pos_top );
651 /*alert( 'Error! HTTP server replied: ' + req.status );*/
656 /* parse browse.xml */
657 function parse_browse_dir( )
659 if( req.readyState == 4 )
661 if( req.status == 200 )
663 var answer = req.responseXML.documentElement;
664 if( !answer ) return;
665 var browser = document.getElementById( 'browser' );
666 var pos = document.createElement( "div" );
667 var elt = answer.firstChild;
670 if( elt.nodeName == "element" )
672 var item = document.createElement( "a" );
673 setclass( item, 'browser' );
674 if( elt.getAttribute( 'type' ) == 'directory' )
676 item.setAttribute( 'href', 'javascript:browse_dir(\''+addslashes(escapebackslashes(elt.getAttribute( 'path' )))+'\');');
680 item.setAttribute( 'href', 'javascript:browse_path(\''+addslashes(escapebackslashes(elt.getAttribute( 'path' )))+'\');' );
682 item.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
683 pos.appendChild( item );
684 if( elt.getAttribute( 'type' ) == 'directory' )
686 pos.appendChild( document.createTextNode( ' ' ) );
687 var item = document.createElement( "a" );
688 setclass( item, 'browser' );
689 item.setAttribute( 'href', 'javascript:browse_path(\''+addslashes(escapebackslashes(elt.getAttribute( 'path' )))+'\');');
690 item.appendChild( document.createTextNode( '(select)' ) );
691 pos.appendChild( item );
693 pos.appendChild( document.createElement( "br" ) );
695 elt = elt.nextSibling;
697 clear_children( browser );
698 browser.appendChild( pos );
702 /*alert( 'Error! HTTP server replied: ' + req.status );*/
707 /**********************************************************************
708 * Input dialog functions
709 *********************************************************************/
710 function hide_input( )
712 document.getElementById( 'input_file' ).style.display = 'none';
713 document.getElementById( 'input_disc' ).style.display = 'none';
714 document.getElementById( 'input_network' ).style.display = 'none';
715 document.getElementById( 'input_fake' ).style.display = 'none';
718 /* update the input MRL using data from the input file helper */
719 /* FIXME ... subs support */
720 function update_input_file()
722 var mrl = document.getElementById( 'input_mrl' );
724 mrl.value = value( 'input_file_filename' );
727 /* update the input MRL using data from the input disc helper */
728 function update_input_disc()
730 var mrl = document.getElementById( 'input_mrl' );
731 var type = radio_value( "input_disc_type" );
732 var device = value( "input_disc_dev" );
734 var title = check_and_replace_int( 'input_disc_title', 0 );
735 var chapter = check_and_replace_int( 'input_disc_chapter', 0 );
736 var subs = check_and_replace_int( 'input_disc_subtrack', '' );
737 var audio = check_and_replace_int( 'input_disc_audiotrack', 0 );
743 mrl.value += "dvd://";
745 else if( type == "dvdsimple" )
747 mrl.value += "dvdsimple://";
749 else if( type == "vcd" )
751 mrl.value += "vcd://";
753 else if( type == "cdda" )
755 mrl.value += "cdda://";
762 mrl.value += "@"+title;
763 if( chapter && type != "cdda" )
764 mrl.value += ":"+chapter;
770 mrl.value += " :sub-track="+subs;
772 mrl.value += " :audio-track="+audio;
777 /* update the input MRL using data from the input network helper */
778 function update_input_net()
780 var mrl = document.getElementById( 'input_mrl' );
781 var type = radio_value( "input_net_type" );
783 check_and_replace_int( 'input_net_udp_port', 1234 );
784 check_and_replace_int( 'input_net_udpmcast_port', 1234 );
790 mrl.value += "udp://";
791 if( checked( 'input_net_udp_forceipv6' ) )
793 if( value( 'input_net_udp_port' ) )
794 mrl.value += ":"+value( 'input_net_udp_port' );
796 else if( type == "udpmcast" )
798 mrl.value += "udp://@"+value( 'input_net_udpmcast_address');
799 if( value( 'input_net_udpmcast_port' ) )
800 mrl.value += ":"+value( 'input_net_udpmcast_port' );
802 else if( type == "http" )
804 var url = value( 'input_net_http_url' );
805 if( url.substring(0,7) != "http://"
806 && url.substring(0,8) != "https://"
807 && url.substring(0,6) != "ftp://"
808 && url.substring(0,6) != "mms://"
809 && url.substring(0,7) != "mmsh://" )
810 mrl.value += "http://";
813 else if( type == "rtsp" )
815 var url = value( 'input_net_rtsp_url' );
816 if( url.substring(0,7) != "rtsp://" )
817 mrl.value += "rtsp://";
821 if( checked( "input_net_timeshift" ) )
822 mrl.value += " :access-filter=timeshift";
825 /* update the input MRL using data from the input fake helper */
826 function update_input_fake()
828 var mrl = document.getElementById( 'input_mrl' );
830 mrl.value = "fake://";
831 mrl.value += " :fake-file=" + value( "input_fake_filename" );
833 if( value( "input_fake_width" ) )
834 mrl.value += " :fake-width=" + value( "input_fake_width" );
835 if( value( "input_fake_height" ) )
836 mrl.value += " :fake-height=" + value( "input_fake_height" );
837 if( value( "input_fake_ar" ) )
838 mrl.value += " :fake-ar=" + value( "input_fake_ar" );
841 /**********************************************************************
842 * Sout dialog functions
843 *********************************************************************/
844 /* toggle show the full sout interface */
845 function toggle_show_sout_helper()
847 var element = document.getElementById( "sout_helper" );
848 if( element.style.display == 'block' )
850 element.style.display = 'none';
851 document.getElementById( "sout_helper_toggle" ).value = 'Full sout interface';
855 element.style.display = 'block';
856 document.getElementById( "sout_helper_toggle" ).value = 'Hide sout interface';
860 /* update the sout MRL using data from the sout_helper */
861 function update_sout()
863 var mrl = document.getElementById( 'sout_mrl' );
866 check_and_replace_int( 'sout_http_port', 8080 );
867 check_and_replace_int( 'sout_mmsh_port', 8080 );
868 check_and_replace_int( 'sout_rtp_port', 1234 );
869 check_and_replace_int( 'sout_udp_port', 1234 );
870 check_and_replace_int( 'sout_ttl', 1 );
872 if( checked( 'sout_soverlay' ) )
874 disable( 'sout_scodec' );
875 disable( 'sout_sub' );
879 enable( 'sout_scodec' );
880 enable( 'sout_sub' );
883 var transcode = checked( 'sout_vcodec_s' ) || checked( 'sout_acodec_s' )
884 || checked( 'sout_sub' ) || checked( 'sout_soverlay' );
888 mrl.value += ":sout=#transcode{";
889 var alot = false; /* alot == at least one transcode */
890 if( checked( 'sout_vcodec_s' ) )
892 mrl.value += "vcodec="+value( 'sout_vcodec' )+",vb="+value( 'sout_vb' )+",scale="+value( 'sout_scale' );
895 if( checked( 'sout_acodec_s' ) )
897 if( alot ) mrl.value += ",";
898 mrl.value += "acodec="+value( 'sout_acodec' )+",ab="+value( 'sout_ab' );
899 if( value( 'sout_channels' ) )
900 mrl.value += ",channels="+value( 'sout_channels' );
903 if( checked( 'sout_soverlay' ) )
905 if( alot ) mrl.value += ",";
906 mrl.value += "soverlay";
909 else if( checked( 'sout_sub' ) )
911 if( alot ) mrl.value += ",";
912 mrl.value += "scodec="+value( 'sout_scodec' );
915 mrl.value += value( 'sout_transcode_extra' );
920 var output = checked( 'sout_display' ) + checked( 'sout_file' )
921 + checked( 'sout_http' ) + checked( 'sout_mmsh' )
922 + checked( 'sout_rtp' ) + checked( 'sout_udp' );
929 mrl.value += ":sout=#";
930 var aloo = false; /* aloo == at least one output */
931 var mux = radio_value( 'sout_mux' );
932 var ttl = parseInt( value( 'sout_ttl' ) );
933 if( output > 1 ) mrl.value += "duplicate{";
934 if( checked( 'sout_display' ) )
936 if( output > 1 ) mrl.value += "dst="
937 mrl.value += "display";
940 if( checked( 'sout_file' ) )
942 if( aloo ) mrl.value += ",";
943 if( output > 1 ) mrl.value += "dst="
944 mrl.value += "std{access=file,mux="+mux+",dst="+value( 'sout_file_filename' )+"}";
947 if( checked( 'sout_http' ) )
949 if( aloo ) mrl.value += ",";
950 if( output > 1 ) mrl.value += "dst="
951 mrl.value += "std{access=http,mux="+mux+",dst="+value( 'sout_http_addr' );
952 if( value( 'sout_http_port' ) )
953 mrl.value += ":"+value( 'sout_http_port' );
957 if( checked( 'sout_mmsh' ) )
959 if( aloo ) mrl.value += ",";
960 if( output > 1 ) mrl.value += "dst="
961 mrl.value += "std{access=mmsh,mux="+mux+",dst="+value( 'sout_mmsh_addr' );
962 if( value( 'sout_mmsh_port' ) )
963 mrl.value += ":"+value( 'sout_mmsh_port' );
967 if( checked( 'sout_rtp' ) )
969 if( aloo ) mrl.value += ",";
970 if( output > 1 ) mrl.value += "dst="
971 mrl.value += "std{access=rtp";
972 if( ttl ) mrl.value += "{ttl="+ttl+"}";
973 mrl.value += ",mux="+mux+",dst="+value( 'sout_rtp_addr' );
974 if( value( 'sout_rtp_port' ) )
975 mrl.value += ":"+value( 'sout_rtp_port' );
976 if( checked( 'sout_sap' ) )
979 if( value( 'sout_sap_group' ) != '' )
981 mrl.value += ",group=\""+value( 'sout_sap_group' )+"\"";
983 mrl.value += ",name=\""+value( 'sout_sap_name' )+"\"";
988 if( checked( 'sout_udp' ) )
990 if( aloo ) mrl.value += ",";
991 if( output > 1 ) mrl.value += "dst="
992 mrl.value += "std{access=udp";
993 if( ttl ) mrl.value += "{ttl="+ttl+"}";
994 mrl.value += ",mux="+mux+",dst="+value( 'sout_udp_addr' );
995 if( value('sout_udp_port' ) )
996 mrl.value += ":"+value( 'sout_udp_port' );
997 if( checked( 'sout_sap' ) )
1000 if( value( 'sout_sap_group' ) != '' )
1002 mrl.value += ",group=\""+value( 'sout_sap_group' )+"\"";
1004 mrl.value += ",name=\""+value( 'sout_sap_name' )+"\"";
1009 if( output > 1 ) mrl.value += "}";
1012 if( ( transcode || output ) && checked( 'sout_all' ) )
1013 mrl.value += " :sout-all";
1016 /* reset sout mrl value */
1017 function reset_sout()
1019 document.getElementById('sout_mrl').value = value('sout_old_mrl');
1022 /* save sout mrl value */
1023 function save_sout()
1025 document.getElementById('sout_old_mrl').value = value('sout_mrl');
1028 /**********************************************************************
1029 * Browser dialog functions
1030 *********************************************************************/
1031 /* only browse() should be called directly */
1032 function browse( dest )
1034 document.getElementById( 'browse_dest' ).value = dest;
1035 document.getElementById( 'browse_lastdir' ).value;
1036 browse_dir( document.getElementById( 'browse_lastdir' ).value );
1039 function browse_dir( dir )
1041 document.getElementById( 'browse_lastdir' ).value = dir;
1042 loadXMLDoc( 'requests/browse.xml?dir='+encodeURIComponent(dir), parse_browse_dir );
1044 function browse_path( p )
1046 document.getElementById( value( 'browse_dest' ) ).value = p;
1048 document.getElementById( value( 'browse_dest' ) ).focus();
1050 function refresh_albumart( force )
1052 if( albumart_id != pl_cur_id || force )
1054 var now = new Date();
1055 var albumart = document.getElementById( 'albumart' );
1056 albumart.src = '/art?timestamp=' + now.getTime();
1057 albumart_id = pl_cur_id;
1060 /**********************************************************************
1061 * Periodically update stuff in the interface
1062 *********************************************************************/
1063 function loop_refresh_status()
1065 setTimeout( 'loop_refresh_status()', 1000 );
1068 function loop_refresh_playlist()
1070 /* setTimeout( 'loop_refresh_playlist()', 10000 ); */
1073 function loop_refresh_albumart()
1075 setTimeout( 'loop_refresh_albumart()', 1000 );
1076 refresh_albumart( false );
1078 function loop_refresh()
1080 setTimeout( 'loop_refresh_status()', 1 );
1081 setTimeout( 'loop_refresh_playlist()', 1 );
1082 setTimeout( 'loop_refresh_albumart()', 1 );