File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change 22
22
overflow : hidden;
23
23
margin-bottom : 2px ;
24
24
}
25
- # browser a : hover , # playlist a : hover { background : # 200A46 ; color : white; }
26
25
# browser { background : # 8C9A20 ; }
27
26
# browser a .dir { background : # BECD53 ; color : black; }
28
27
# browser a .file { background : # 5A640A ; color : white; }
29
28
# playlist { background : # 881C46 ; }
30
29
# playlist a { background : # C44F7C ; }
31
30
# 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 ; }
32
34
</ style >
33
35
< script src ="http://www.google.com/jsapi " type ="text/javascript "> </ script >
34
36
< script type ="text/javascript ">
35
37
var root = "/f/" ;
36
38
var path = [ ] ;
37
39
function init ( ) {
38
40
load ( path ) ;
41
+ $ ( '#player' ) . bind ( 'ended' , next ) ;
42
+ $ ( '#addall' ) . click ( addAll ) ;
39
43
}
40
44
function load ( path ) {
41
45
$ . ajax ( {
85
89
. click ( function ( e ) { play ( e . target ) ; } ) ;
86
90
if ( playnow ) $d . click ( ) ;
87
91
}
92
+ function addAll ( ) {
93
+ $ ( '#browser a.file' ) . each ( function ( i , e ) {
94
+ addToPlaylist ( $ ( e ) . data ( 'file' ) ) ;
95
+ } ) ;
96
+ }
88
97
function play ( el ) {
89
98
var name = $ ( el ) . data ( 'file' ) . Name ;
90
99
var url = root + path . join ( '/' ) + '/' + name ;
106
115
</ audio >
107
116
< div id ="browser "> </ div >
108
117
< div id ="playlist "> </ div >
118
+ < div id ="controls ">
119
+ < a id ="addall "> Add all to playlist</ div >
120
+ </ div >
109
121
</ body >
110
122
</ html >
Original file line number Diff line number Diff line change @@ -3,8 +3,12 @@ package main
3
3
import (
4
4
"flag"
5
5
"http"
6
+ "io"
6
7
"json"
7
8
"os"
9
+ "mime"
10
+ "path"
11
+ "strconv"
8
12
)
9
13
10
14
const (
@@ -38,7 +42,18 @@ func File(w http.ResponseWriter, r *http.Request) {
38
42
serveDirectory (fn , w , r )
39
43
return
40
44
}
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 )
42
57
}
43
58
44
59
func serveDirectory (fn string , w http.ResponseWriter , r * http.Request ) {
You can’t perform that action at this time.
0 commit comments