From: AceVest Date: Sun, 17 Jan 2021 14:29:31 +0000 (+0800) Subject: add audio player web X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/doc/roff.3.ps?a=commitdiff_plain;h=223424b481faf9939ddbb11efe58f322f12f3813;p=acecode.git add audio player web --- diff --git a/projects/audio_stream/audioweb/canvas.html b/projects/audio_stream/audioweb/canvas.html deleted file mode 100644 index 06d1810..0000000 --- a/projects/audio_stream/audioweb/canvas.html +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - CANVAS VIDEO - - - - - -

-    

-
-    
-
-
-
diff --git a/projects/audio_stream/audioweb/main.go b/projects/audio_stream/audioweb/main.go
index e0ece94..4c4cec5 100644
--- a/projects/audio_stream/audioweb/main.go
+++ b/projects/audio_stream/audioweb/main.go
@@ -32,40 +32,9 @@ var upgrader = websocket.Upgrader{
 var frameChan chan []byte
 
 func init() {
-	frameChan = make(chan []byte, 8)
+	frameChan = make(chan []byte, 128)
 }
 
-const (
-	partBOUNDARY      = "123456789000000000000987654321"
-	streamContentType = "multipart/x-mixed-replace;boundary=" + partBOUNDARY
-	streamBoundary    = "\r\n--" + partBOUNDARY + "\r\n"
-	streamPart        = "Content-Type: image/jpeg\r\nContent-Length: %d\r\n\r\n"
-)
-
-func watchHandler(w http.ResponseWriter, r *http.Request) {
-	var err error
-	w.Header().Set("Content-Type", streamContentType)
-	w.Header().Set("Access-Control-Allow-Origin", "*")
-
-	flusher, _ := w.(http.Flusher)
-
-	for i := 0; ; i++ {
-		var data []byte
-		select {
-		case data = <-frameChan:
-			fmt.Fprintf(w, "%v", streamBoundary)
-			fmt.Fprintf(w, streamPart, i)
-			_, err = w.Write(data)
-			flusher.Flush()
-			if err != nil {
-				break
-			}
-		default:
-			continue
-		}
-
-	}
-}
 
 func audioHandler(w http.ResponseWriter, r *http.Request) {
 	var err error
@@ -151,8 +120,8 @@ func streamHandler(w http.ResponseWriter, r *http.Request) {
 	}
 }
 
-func canvasHandler(w http.ResponseWriter, r *http.Request) {
-	tmpl := template.Must(template.ParseFiles("./canvas.html"))
+func playerHandler(w http.ResponseWriter, r *http.Request) {
+	tmpl := template.Must(template.ParseFiles("./player.html"))
 	var data = map[string]interface{}{}
 	tmpl.Execute(w, data)
 }
@@ -161,9 +130,8 @@ func main() {
 	defer fmt.Println("Program Exited...")
 
 	m := http.NewServeMux()
-	m.HandleFunc("/watch", watchHandler)
 	m.HandleFunc("/audio", audioHandler)
-	m.HandleFunc("/canvas", canvasHandler)
+	m.HandleFunc("/player", playerHandler)
 	m.HandleFunc("/stream", streamHandler)
 	server := http.Server{
 		Addr:    ":80",
diff --git a/projects/audio_stream/audioweb/player.html b/projects/audio_stream/audioweb/player.html
new file mode 100644
index 0000000..0f5ec59
--- /dev/null
+++ b/projects/audio_stream/audioweb/player.html
@@ -0,0 +1,140 @@
+
+
+
+
+    
+    AUDIO PLAYER
+    
+
+
+
+    
+    

+    

+
+    
+
+
+