2 Pitchfork Music Player Daemon Client
3 Copyright (C) 2007 Roger Bystrøm
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 var streaming_info = null;
21 function StreamingInfo() {
24 var c = setting_get("sap");
26 this.auto_play = true;
27 setting_set("sap", "true");
30 this.auto_play = c=="true"?true:false;
32 this.auto_play_node = null;
34 this.notification_txt = null;
35 this.check_delay = 0.3 * 1000;
36 this.eventListeners = new Array();
39 function streaming_init() {
40 streaming_info = new StreamingInfo();
43 function streaming_destroy() {
44 while(streaming_info.eventListeners.length)
45 streaming_info.eventListeners.pop().unregister();
47 remove_node(streaming_info.applet);
48 remove_node(streaming_info.auto_play_node);
49 remove_node(streaming_info.notification_txt);
50 remove_node(streaming_info.display);
52 streaming_info.applet = null;
53 streaming_info.auto_play_node = null;
54 streaming_info.notification_txt = null;
55 streaming_info.display = null;
57 streaming_info.open = false;
60 function streaming_open(e) {
61 var s =streaming_info.display;
63 s = create_node("div", "streaming_display");
64 var d2 = create_node("div");
65 d2.style.marginLeft = "5px";
68 /* if someone can make this work in all browsers and not crash/hang
69 anyone of them I'd like to know... */
71 function make_item(txt) {
72 var item = create_node("li");
73 item.className = "fakelink";
74 item.style.borderLeft = item.style.borderRight = "none";
79 var obj = "<applet type='application/x-java-applet'" +
82 " id='streamplayer'" +
83 " style='display: inline; visibility: hidden; position: absolute;'" +
84 " archive='../jorbis/jorbis-pitchfork.jar'" +
85 " classid='java:JOrbisPlayer.class'" +
86 " code='JOrbisPlayer.class'" +
87 "<param name='archive' value='../jorbis/jorbis-pitchfork.jar' />" +
88 (streaming_info.auto_play?"<param name='jorbis.player.playonstartup' value='yes' />":"") +
89 "<param name='jorbis.player.play.0' value='"+SHOUT_URL+"' />" +
90 "<param name='jorbis.player.bgcolor' value='" + IMAGE.STREAM_BGCOLOR + "' />" +
94 var txt = create_node("ul");
95 //txt.className = "fakelink";
96 txt.className = "nomargin";
97 //txt.style.margin = "0px 2px 0px 0px";
98 txt.style.padding = "0px 0px 0px 0px";
99 txt.style.fontSize = "smaller";
101 var sp = create_node("span");
102 sp.style.fontWeight = "bold";
103 sp.style.padding = "5px 0px 5px 0px";
104 add_txt(sp, LANG.STREAMING);
107 var item = make_item(LANG.CLOSE);
108 streaming_info.eventListeners.push(add_listener(item, "click", streaming_destroy));
109 txt.appendChild(item);
111 item = make_item(LANG.HIDE);
112 streaming_info.eventListeners.push(add_listener(item, "click", streaming_hide));
113 txt.appendChild(item);
115 item = make_item( streaming_info.auto_play?LANG.AUTOPLAY:LANG.NO_AUTOPLAY );
116 txt.appendChild(item);
117 streaming_info.eventListeners.push(add_listener(item, "click", streaming_toggle_auto_play));
118 streaming_info.auto_play_node = item;
120 item = make_item("");
121 streaming_info.notification_txt = item;
122 txt.appendChild(streaming_info.notification_txt);
123 streaming_info.eventListeners.push(add_listener(streaming_info.notification_txt, "click", streaming_toggle_event));
125 // insert container first in area
126 insert_first(txt, s);
128 document.getElementById('player_control').appendChild(s);
129 streaming_info.display = s;
130 streaming_info.applet = document.applets['streamplayer'];
132 streaming_check_playing();
133 document.body.focus();
135 if(streaming_info.open) {
139 s.style.visibility = "";
140 streaming_info.open = true;
141 streaming_try_autoplay();
148 /* hides the whole streaming area */
149 function streaming_hide(e) {
150 if(streaming_info.display) {
151 streaming_info.display.style.visibility = "hidden";
153 streaming_info.open = false;
159 /* toggles the autoplay feature */
160 function streaming_toggle_auto_play(e) {
162 if(streaming_info.auto_play_node) {
163 var s = streaming_info.auto_play_node;
165 streaming_info.auto_play = !streaming_info.auto_play;
166 add_txt(s, streaming_info.auto_play?LANG.AUTOPLAY:LANG.NO_AUTOPLAY);
167 setting_set("sap", streaming_info.auto_play?"true":"false");
171 /* checks whether the applet is currently streaming or not,
172 * returns false on error or non-existing applet */
173 function streaming_is_playing() {
174 if(streaming_info.applet) {
176 return streaming_info.applet.isPlaying();
182 /* tries to start playback if the applet is available */
183 function streaming_try_play() {
184 if(streaming_info.applet) {
186 streaming_info.applet.play_sound();
191 /* tries to stop playback if the applet is available */
192 function streaming_try_stop() {
193 if(streaming_info.applet) {
195 streaming_info.applet.stop_sound();
200 /* tries to start playing if autoplay is enabled */
201 function streaming_try_autoplay() {
202 if(streaming_info.auto_play&&streaming_info.display&&streaming_info.applet) {
203 streaming_try_play();
207 /* tries to stop the audio playback if autoplay is enabled */
208 function streaming_try_autostop() {
209 if(streaming_info.auto_play&&streaming_info.display) {
210 streaming_try_stop();
214 function streaming_update_stat() {
215 remove_children(streaming_info.notification_txt);
216 streaming_info.notification_txt.appendChild(create_txt(streaming_info.stat?LANG.STOP:LANG.PLAY));
219 function streaming_check_playing() {
220 var stat = streaming_is_playing();
221 if(streaming_info.stat != stat) {
222 streaming_info.stat = stat;
223 streaming_update_stat();
225 setTimeout(streaming_check_playing, streaming_info.check_delay);
227 function streaming_toggle_event(e) {
229 if(!streaming_is_playing()) {
230 streaming_try_play();
232 streaming_try_stop();