Skip to content

Commit ee5ce12

Browse files
added README, auto-advance works
1 parent 2d9e451 commit ee5ce12

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

README

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
GoPlayer, an HTML5 and Go-based music player
2+
3+
I have a large music collection on a machine at home,
4+
and I want to be able to listen to that music at work.
5+
This is my solution to that problem.
6+
7+
Andrew Gerrand <[email protected]>
8+

index.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,24 @@
2222
overflow: hidden;
2323
margin-bottom: 2px;
2424
}
25-
#browser a:hover, #playlist a:hover { background: #200A46; color: white; }
2625
#browser { background: #8C9A20; }
2726
#browser a.dir { background: #BECD53; color: black; }
2827
#browser a.file { background: #5A640A; color: white; }
2928
#playlist { background: #881C46; }
3029
#playlist a { background: #C44F7C; }
3130
#playlist a.playing { background: #3B1E6C; color: white; }
31+
#browser a:hover, #playlist a:hover { background: #200A46; color: white; }
32+
#controls { margin-top: 10px; }
33+
#addall { cursor: pointer; background: #eee; padding: 5px; border-radius: 5px; }
3234
</style>
3335
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
3436
<script type="text/javascript">
3537
var root = "/f/";
3638
var path = [];
3739
function init() {
3840
load(path);
41+
$('#player').bind('ended', next);
42+
$('#addall').click(addAll);
3943
}
4044
function load(path) {
4145
$.ajax({
@@ -85,6 +89,11 @@
8589
.click(function(e) { play(e.target); });
8690
if (playnow) $d.click();
8791
}
92+
function addAll() {
93+
$('#browser a.file').each(function(i, e) {
94+
addToPlaylist($(e).data('file'));
95+
});
96+
}
8897
function play(el) {
8998
var name = $(el).data('file').Name;
9099
var url = root+path.join('/')+'/'+name;
@@ -106,5 +115,8 @@
106115
</audio>
107116
<div id="browser"></div>
108117
<div id="playlist"></div>
118+
<div id="controls">
119+
<a id="addall">Add all to playlist</div>
120+
</div>
109121
</body>
110122
</html>

player.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ package main
33
import (
44
"flag"
55
"http"
6+
"io"
67
"json"
78
"os"
9+
"mime"
10+
"path"
11+
"strconv"
812
)
913

1014
const (
@@ -38,7 +42,18 @@ func File(w http.ResponseWriter, r *http.Request) {
3842
serveDirectory(fn, w, r)
3943
return
4044
}
41-
http.ServeFile(w, r, fn)
45+
f, err := os.Open(fn, os.O_RDONLY, 0)
46+
if err != nil {
47+
http.Error(w, err.String(), http.StatusInternalServerError)
48+
return
49+
}
50+
t := mime.TypeByExtension(path.Ext(fn))
51+
if t == "" {
52+
t = "application/octet-stream"
53+
}
54+
w.SetHeader("Content-Type", t)
55+
w.SetHeader("Content-Length", strconv.Itoa64(fi.Size))
56+
io.Copy(w, f)
4257
}
4358

4459
func serveDirectory(fn string, w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)