aboutsummaryrefslogtreecommitdiffstats
path: root/package/fonera-mp3/src/cgi/json.js
blob: 721d5273eb5a606e11f6461b2b74b172629ee6ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var alpmp3_playtime = 0;
var alpmp3_state = 0;
var alpmp3_ip = "";
var obj_volume; 
var obj_bass; 
var obj_playtime; 
var obj_sate; 
var obj_filename; 
var MP3Object;
var is_setup = 0;

function alpmp3_ajax_new_data(){
	obj_bass.firstChild.nodeValue = MP3Object.alpmp3.bass;
	obj_volume.firstChild.nodeValue = MP3Object.alpmp3.volume;
	obj_state.firstChild.nodeValue = MP3Object.alpmp3.type;
	obj_filename.firstChild.nodeValue = MP3Object.alpmp3.filename;
	alpmp3_state = MP3Object.alpmp3.state;
	if(Math.abs(alpmp3_playtime - MP3Object.alpmp3.playtime) > 1){
		alpmp3_playtime = MP3Object.alpmp3.playtime;
	}
}

function alpmp3_update_data(url){
	var data;
	var http_request = new XMLHttpRequest();
	http_request.open("GET", url, true);
	http_request.onreadystatechange = function () {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				MP3Object = eval("(" + http_request.responseText + ")");
				alpmp3_ajax_new_data();
			} else {	
				alert("There was a problem with the URL.");
			}
			http_request = null;
		}
	}
	http_request.send(null);
	self.setTimeout("alpmp3_update_data('mp3_json.cgi');", 4000);
}

function alpmp3_remote(cmd){
	var doit = "";	
	switch(cmd){
	case 'volup':
		if(MP3Object.alpmp3.volume < 30){
			MP3Object.alpmp3.volume++;
		}
		doit = "?vol=" + MP3Object.alpmp3.volume;
		break;
	case 'voldown':
		if(MP3Object.alpmp3.volume > 0){
			MP3Object.alpmp3.volume--;
		}
		doit = "?vol=" + MP3Object.alpmp3.volume;
		break;
	case 'bassup':
		if(MP3Object.alpmp3.bass < 30){
			MP3Object.alpmp3.bass++;
		}
		doit = "?bass=" + MP3Object.alpmp3.bass;
		break;
	case 'bassdown':
		if(MP3Object.alpmp3.volume < 30){
			MP3Object.alpmp3.bass--;
		}
		doit = "?bass=" + MP3Object.alpmp3.bass;
		break;
	case 'stop':
		doit = "?stop=1";
		break;
	case 'start':
		doit = "?start=1";
		break;
	case 'next':
		doit = "?next=1";
		break;
	case 'back':
		doit = "?back=1";
		break;
	}
	if(doit != ""){
		var http_request2 = new XMLHttpRequest();
		http_request2.open("GET", 'mp3_cmd.cgi'+doit, true);
		http_request2.onreadystatechange = function () {
			if (http_request2.readyState == 4) {
				if (http_request2.status == 200) {
					alpmp3_ajax_new_data();
				} else {	
					alert("There was a problem with the URL.");
				}
				http_request2 = null;
			}
		}
		http_request2.send(null);
	}

}

function alpmp3_timeout(){
	alpmp3_state = 0;
	alert(alpmp3_playtime);
}

function alpmp3_playtime_update(){
	self.setTimeout("alpmp3_playtime_update()", 1000);
	if(alpmp3_state > 0){
		alpmp3_playtime ++;
	} else {
		alpmp3_playtime = 0;
	}
	var s = alpmp3_playtime;
	var h = 0;
	var m = 0;
	while(s > 3599){
		h++;
		s -= 3600;
	}
	while(s > 59){
		m++;
		s -= 60;
	}
	ptime = ((m < 10) ? "0" : "") + m + ":" + ((s < 10) ? "0" : "") + s;
	if(h > 0){
		ptime = ((h < 10) ? "0" : "") + h + ":" + ptime;
	}
	obj_playtime.firstChild.nodeValue = ptime;
}

function alpmp3_setup($ip){
	if(is_setup == 0){
		obj_volume = document.getElementById("alpmp3_volume");
		obj_bass = document.getElementById("alpmp3_bass");
		obj_state = document.getElementById("alpmp3_state");
		obj_filename = document.getElementById("alpmp3_filename");
		obj_playtime = document.getElementById("alpmp3_playtime");
		is_setup = 1;
	}
	self.setTimeout("alpmp3_update_data('mp3_json.cgi');", 4000);
	self.setTimeout("alpmp3_playtime_update()", 1000);
}