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