wplayer

Check-in [0980e94b4f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Clean up layout. Ready to code file positioning. OGG file type.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:0980e94b4fdca69f1435395d270e02b2dadb4d092a9e9e383d87d444691b6cef
User & Date: ajv-899-334-8894@vsta.org 2016-01-27 22:48:38
Context
2016-01-28
04:35
Some images for our controls. From /usr/share/icons/gnome, so please use under the terms of the Gnome project (http://gnome.org) check-in: c24fd39b82 user: ajv-899-334-8894@vsta.org tags: master, trunk
2016-01-27
22:48
Clean up layout. Ready to code file positioning. OGG file type. check-in: 0980e94b4f user: ajv-899-334-8894@vsta.org tags: master, trunk
17:00
Bringup; files now play check-in: b9c87d983f user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to chore/handlers.py.

159
160
161
162
163
164
165


166
167
168
169
170
171
172
...
196
197
198
199
200
201
202



203
204
205
206
207
208
209
...
277
278
279
280
281
282
283
284

285
286
287
288
289
290


291


292
293
294
295
296
297
298
	    return True,"image/gif"
	if fn.endswith(".wav"):
	    return True,"audio/x-wav"
	if fn.endswith(".mp3"):
	    return True,"audio/mpeg"
	if fn.endswith(".flac"):
	    return True,"audio/flac"


	if fn.endswith(".html"):
	    return False,"text/html"
	if fn.endswith(".htm"):
	    return False,"text/html"
	if fn.endswith(".txt"):
	    return False,"text/plain"
	if fn.endswith(".json"):
................................................................................
	    f = open(fn, "r")
	except:
	    self.send_error(404, "File not found")
	    return None
	buf = f.read()
	f.close()




	buf = self.send_result(buf, mtyp, binary=isbin)
	return buf

    # Common code to strip and decode options
    # Also bursts the path to self.paths[]
    def options(self):
	p = self.path
................................................................................

	# Ok
	return True

    # Send header
    # Also canonicalize to DOS-style line endings (ew)
    def send_result(self, buf,
	    mtype="text/html", cacheable=False, binary=False):


	# Rewrite to DOS line endings unless it's binary
	#  (mp3 audio, etc.)
	if not binary:
	    buf = buf.replace("\n", "\r\n")



        self.send_response(200)


        self.send_header("Content-type", mtype)
        self.send_header("Content-Length", len(buf))
	if not cacheable:
	    self.send_header("Cache-Control", "NoCache")
	else:
	    self.send_header("Last-Modified",
		time.asctime(time.localtime(self.changed)))







>
>







 







>
>
>







 







|
>






>
>
|
>
>







159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
...
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
	    return True,"image/gif"
	if fn.endswith(".wav"):
	    return True,"audio/x-wav"
	if fn.endswith(".mp3"):
	    return True,"audio/mpeg"
	if fn.endswith(".flac"):
	    return True,"audio/flac"
	if fn.endswith(".ogg"):
	    return True,"audio/ogg"
	if fn.endswith(".html"):
	    return False,"text/html"
	if fn.endswith(".htm"):
	    return False,"text/html"
	if fn.endswith(".txt"):
	    return False,"text/plain"
	if fn.endswith(".json"):
................................................................................
	    f = open(fn, "r")
	except:
	    self.send_error(404, "File not found")
	    return None
	buf = f.read()
	f.close()

	if self.vals and ("range" in str(self.vals.keys()).lower()):
	    import pdb
	    pdb.set_trace()
	buf = self.send_result(buf, mtyp, binary=isbin)
	return buf

    # Common code to strip and decode options
    # Also bursts the path to self.paths[]
    def options(self):
	p = self.path
................................................................................

	# Ok
	return True

    # Send header
    # Also canonicalize to DOS-style line endings (ew)
    def send_result(self, buf,
	    mtype="text/html", cacheable=False, binary=False,
	    code=None):

	# Rewrite to DOS line endings unless it's binary
	#  (mp3 audio, etc.)
	if not binary:
	    buf = buf.replace("\n", "\r\n")

	# Override for partial response
	if code is None:
	    self.send_response(200)
	else:
	    self.send_response(code)
        self.send_header("Content-type", mtype)
        self.send_header("Content-Length", len(buf))
	if not cacheable:
	    self.send_header("Cache-Control", "NoCache")
	else:
	    self.send_header("Last-Modified",
		time.asctime(time.localtime(self.changed)))

Changes to html/top.html.

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
<html>
<head>
<title>Web Player</title>
</head>
<body>
 <table>
  <tr style="height: 50%; outline: thin solid black;">
   <span id="pqueue"></span></tr>
  <tr style="height: 50%; outline: thin solid black;">
   <span id="nowplaying"></span><br>



   <button onclick="return seek(-600);">-10m</button>
   <button onclick="return seek(-60);">-1m</button>
   <button onclick="return seek(-10);">-10s</button>


   <audio controls id="player">
   </audio>


   <button onclick="return seek(10);">+10s</button>
   <button onclick="return seek(60);">+1m</button>
   <button onclick="return seek(600);">+10m</button>

  </tr>
  <tr style="height: 50%; outline: thin solid black;">
   <span id="browser"></span></tr>
 </table>


 <script src="/js/player.js"></script>
</body>
</html>


|


|
|
<
<
|
>
>
>
|
|
|
>
>
|
<
>
>
|
|
|
>

<
<

>
>



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
<html>
<head>
 <title>Web Player</title>
</head>
<body>
 <textarea rows="8" cols="80" readonly id="pqueue"></textarea>
 <hr>


 <span id="nowplaying"></span><br>
 <table>
  <tr>
   <td>
    <button onclick="return seek(-600);">-10m</button><br>
    <button onclick="return seek(-60);">-1m</button><br>
    <button onclick="return seek(-10);">-10s</button>
   </td>
   <td>
    <audio controls id="player"></audio>

   </td>
   <td>
    <button onclick="return seek(10);">+10s</button><br>
    <button onclick="return seek(60);">+1m</button><br>
    <button onclick="return seek(600);">+10m</button>
   </td>
  </tr>


 </table>
 <hr>
 <span id="browser"></span>
 <script src="/js/player.js"></script>
</body>
</html>

Changes to js/player.js.

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
...
103
104
105
106
107
108
109

110
111
112
113
114
115
116
...
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
138
139
140

141
142
143
144
145
146
147

148
149
150
151
        return;
    }

    // Decode JSON
    pcontents = JSON.parse(req.responseText);

    // Paint file browsing window
    var res = '<hr><button onclick="go_up();">Go Up</button><br>'



    // Directories (if any)
    if (pcontents.dirs.length > 0) {
	res += '<b>Directories</b>:<br>';
	var d, didx = 0;
	while (didx < pcontents.dirs.length) {
	    d = pcontents.dirs[didx];
	    res += '<button onclick="go_dir(' + didx.toString() + ');">'
	    res += d;
	    res += '</button><br>\n';
	    didx += 1;
	}
    }

    // Files (if any)
    if (pcontents.files.length > 0) {
	res += '<b>Files</b>:<br>';
	var f, fidx = 0;
	while (fidx < pcontents.files.length) {
	    f = pcontents.files[fidx];
	    res += '<button onclick="go_file(' + fidx.toString() + ');">'
	    res += f;
	    res += '</button><br>\n';
	    fidx += 1;
	}
    }

    // Replace the HTML
    browser.innerHTML = res;
}
................................................................................
}

// End of current track, try to advance
function playNext() {
    if (playlist.length > 0) {
	nowplaying.textContent = player.src = playlist.shift();
	paintQueue();

    } else {
	player.removeEventListener("ended", playNext);
	playing = false;
	nowplaying.textContent = '';
    }
}

................................................................................
	player.addEventListener("ended", playNext);
	player.play();
	playing = true;
    } else {
	playlist.push(fname);
	paintQueue();
    }

}

// Go up a level
function go_up() {
    if (pdepth == 0) {
	return;
    }
    var idx = path.lastIndexOf("/");
    path = path.slice(0, idx);
    pdepth -= 1;
    curdir();

}

// Push to dir
function go_dir(didx) {
    path = path + "/" + pcontents.dirs[didx];
    pdepth += 1;
    curdir();

}

// Initial browser window update
curdir();







|
>
>







|
|
|










|
|
|







 







>







 







>











>







>




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
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
        return;
    }

    // Decode JSON
    pcontents = JSON.parse(req.responseText);

    // Paint file browsing window
    var res = '<button onclick="return go_up();">\n'
    res += ' <img src="/imgs/player_eject.png" alt="Go Up" />\n'
    res += '</button>' + path + "<br>\n"

    // Directories (if any)
    if (pcontents.dirs.length > 0) {
	res += '<b>Directories</b>:<br>';
	var d, didx = 0;
	while (didx < pcontents.dirs.length) {
	    d = pcontents.dirs[didx];
	    res += '<button onclick="return go_dir(' + didx.toString() + ');">'
	    res += ' <img src="/imgs/player_play.png" alt="enter" />\n'
	    res += '</button>' + d + '<br>\n'
	    didx += 1;
	}
    }

    // Files (if any)
    if (pcontents.files.length > 0) {
	res += '<b>Files</b>:<br>';
	var f, fidx = 0;
	while (fidx < pcontents.files.length) {
	    f = pcontents.files[fidx];
	    res += '<button onclick="return go_file(' + fidx.toString() + ');">'
	    res += ' <img src="/imgs/player_play.png" alt="play" />\n'
	    res += '</button>' + f + '<br>\n'
	    fidx += 1;
	}
    }

    // Replace the HTML
    browser.innerHTML = res;
}
................................................................................
}

// End of current track, try to advance
function playNext() {
    if (playlist.length > 0) {
	nowplaying.textContent = player.src = playlist.shift();
	paintQueue();
	player.play();
    } else {
	player.removeEventListener("ended", playNext);
	playing = false;
	nowplaying.textContent = '';
    }
}

................................................................................
	player.addEventListener("ended", playNext);
	player.play();
	playing = true;
    } else {
	playlist.push(fname);
	paintQueue();
    }
    return false;
}

// Go up a level
function go_up() {
    if (pdepth == 0) {
	return;
    }
    var idx = path.lastIndexOf("/");
    path = path.slice(0, idx);
    pdepth -= 1;
    curdir();
    return false;
}

// Push to dir
function go_dir(didx) {
    path = path + "/" + pcontents.dirs[didx];
    pdepth += 1;
    curdir();
    return false;
}

// Initial browser window update
curdir();