Browse Source

前端需要上传播放时长参数

longan 1 năm trước cách đây
mục cha
commit
f6e1f2af7c
1 tập tin đã thay đổi với 15 bổ sung7 xóa
  1. 15 7
      api/v1/ipcast/ipcast.go

+ 15 - 7
api/v1/ipcast/ipcast.go

@@ -7,6 +7,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"github.com/goccy/go-json"
 	"github.com/sirupsen/logrus"
+	"io"
 	"lcfns/model/common/response"
 	ipResp "lcfns/model/ipcast/response"
 	"net/http"
@@ -114,7 +115,7 @@ var ipcastData = `
     "queue": true,
 	"volume": 50,
     "loop": {
-        "duration": 600,
+        "duration": %s,
         "times": 1,
         "gap": 2
     }
@@ -129,24 +130,27 @@ func (api *IpcastApi) PlayAudio(c *gin.Context) {
 	uuidString := hex.EncodeToString(uuid)
 	defer func() {
 		go func() {
-			//播放完后清除数据
+			//数据传输完后清除数据
 			time.Sleep(10 * time.Second)
 			delete(audio, uuidString)
 		}()
 	}()
 	//读取mp3数据
-	mp3, err := c.GetRawData()
+	//mp3, err := c.GetRawData()
+	mp3, err := c.FormFile("mp3")
 	if err != nil {
 		response.FailWithMessage("获取请求参数出错", c)
 		logrus.Error(err)
 		return
 	}
+	open, err := mp3.Open()
+	readAll, err := io.ReadAll(open)
 	//保存到内存
-	audio[uuidString] = mp3
+	audio[uuidString] = readAll
 	//播放
-	data := []byte(fmt.Sprintf(ipcastData, uuidString))
+	t := c.PostForm("timeLength")
+	data := []byte(fmt.Sprintf(ipcastData, uuidString, t))
 	all, err := ipcastService.Common(GetIpcastUrl(c, Play), http.MethodPost, data)
-	fmt.Println("data:", string(data))
 	if err != nil {
 		response.Fail(c)
 		logrus.Error(err)
@@ -154,7 +158,11 @@ func (api *IpcastApi) PlayAudio(c *gin.Context) {
 	}
 	var resp ipResp.PingResp
 	json.Unmarshal(all, &resp)
-	response.OkWithData(resp.Message, c)
+	if resp.Code == 200 {
+		response.OkWithDetailed(resp.Message, "播放成功", c)
+	} else {
+		response.FailWithDetailed(resp.Message, "播放失败", c)
+	}
 }
 
 // AudioSource 给ip音柱播放的url资源