4 Angajamente d81aae959e ... 6d8eb3166a

Autor SHA1 Permisiunea de a trimite mesaje. Dacă este dezactivată, utilizatorul nu va putea trimite nici un fel de mesaj Data
  317699326@qq.com 6d8eb3166a Merge branch 'aj_fix_bug' into debug 6 zile în urmă
  317699326@qq.com 30da95a12b 修改音频播放时长获取 6 zile în urmă
  317699326@qq.com 0b27005961 兼容备用小程序 1 săptămână în urmă
  317699326@qq.com 225dad4af6 新增备份小程序 1 săptămână în urmă
5 a modificat fișierele cu 40 adăugiri și 41 ștergeri
  1. 10 11
      controller/community/question.go
  2. 1 1
      controller/pc/pc.go
  3. 11 12
      controller/public.go
  4. 13 17
      services/media.go
  5. 5 0
      services/sun_code.go

+ 10 - 11
controller/community/question.go

@@ -20,7 +20,6 @@ import (
 	userService "hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/wx_app"
 	"hongze/hongze_yb/utils"
-	"io/ioutil"
 	"os"
 	"path"
 	"strconv"
@@ -269,16 +268,16 @@ func QuestionUploadAudio(c *gin.Context) {
 		return
 	}
 	// 获取音频文件时长
-	fByte, err := ioutil.ReadFile(fpath)
-	if err != nil {
-		response.FailMsg("读取本地文件失败", "QuestionUploadAudio 读取本地文件失败", c)
-		return
-	}
-	if len(fByte) <= 0 {
-		response.FailMsg("文件大小有误", "QuestionUploadAudio 文件大小有误", c)
-		return
-	}
-	seconds, err := services.GetMP3PlayDuration(fByte)
+	//fByte, err := ioutil.ReadFile(fpath)
+	//if err != nil {
+	//	response.FailMsg("读取本地文件失败", "QuestionUploadAudio 读取本地文件失败", c)
+	//	return
+	//}
+	//if len(fByte) <= 0 {
+	//	response.FailMsg("文件大小有误", "QuestionUploadAudio 文件大小有误", c)
+	//	return
+	//}
+	seconds, err := utils.GetVideoPlaySeconds(fpath) //services.GetMP3PlayDuration(fByte)
 	if err != nil {
 		response.FailMsg("读取文件时长失败", "QuestionUploadAudio 读取文件时长失败", c)
 		return

+ 1 - 1
controller/pc/pc.go

@@ -493,7 +493,7 @@ func GetSunCode(c *gin.Context) {
 	if sunCodeUrl == "" {
 		sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
 		if err != nil {
-			response.FailMsg("生成太阳码失败", err.Error(), c)
+			response.FailMsg("生成太阳码失败:err:"+err.Error(), err.Error(), c)
 			return
 		}
 	}

+ 11 - 12
controller/public.go

@@ -24,7 +24,6 @@ import (
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/wx_app"
 	"hongze/hongze_yb/utils"
-	"io/ioutil"
 	"net/url"
 	"os"
 	"path"
@@ -241,17 +240,17 @@ func UploadAudio(c *gin.Context) {
 		response.FailMsg("文件生成失败", "UploadAudio 文件生成失败, Err:"+err.Error(), c)
 		return
 	}
-	// 获取音频文件时长
-	fByte, err := ioutil.ReadFile(fpath)
-	if err != nil {
-		response.FailMsg("读取本地文件失败", "UploadAudio 读取本地文件失败", c)
-		return
-	}
-	if len(fByte) <= 0 {
-		response.FailMsg("文件大小有误", "UploadAudio 文件大小有误", c)
-		return
-	}
-	seconds, err := services.GetMP3PlayDuration(fByte)
+	//// 获取音频文件时长
+	//fByte, err := ioutil.ReadFile(fpath)
+	//if err != nil {
+	//	response.FailMsg("读取本地文件失败", "UploadAudio 读取本地文件失败", c)
+	//	return
+	//}
+	//if len(fByte) <= 0 {
+	//	response.FailMsg("文件大小有误", "UploadAudio 文件大小有误", c)
+	//	return
+	//}
+	seconds, err := utils.GetVideoPlaySeconds(fpath) //services.GetMP3PlayDuration(fByte)
 	if err != nil {
 		response.FailMsg("读取文件时长失败", "UploadAudio 读取文件时长失败", c)
 		return

+ 13 - 17
services/media.go

@@ -1,19 +1,15 @@
 package services
 
-import (
-	"github.com/tosone/minimp3"
-)
-
-// GetMP3PlayDuration 获取MP3的时长
-func GetMP3PlayDuration(mp3Data []byte) (seconds int, err error) {
-	dec, _, err := minimp3.DecodeFull(mp3Data)
-	if err != nil {
-		return 0, err
-	}
-	if dec.Kbps <= 0 {
-		return 0, err
-	}
-	// 音乐时长 = (文件大小(byte) - 128(ID3信息)) * 8(to bit) / (码率(kbps b:bit) * 1000)(kilo bit to bit)
-	seconds = (len(mp3Data) - 128) * 8 / (dec.Kbps * 1000)
-	return seconds, nil
-}
+//// GetMP3PlayDuration 获取MP3的时长
+//func GetMP3PlayDuration(mp3Data []byte) (seconds int, err error) {
+//	dec, _, err := minimp3.DecodeFull(mp3Data)
+//	if err != nil {
+//		return 0, err
+//	}
+//	if dec.Kbps <= 0 {
+//		return 0, err
+//	}
+//	// 音乐时长 = (文件大小(byte) - 128(ID3信息)) * 8(to bit) / (码率(kbps b:bit) * 1000)(kilo bit to bit)
+//	seconds = (len(mp3Data) - 128) * 8 / (dec.Kbps * 1000)
+//	return seconds, nil
+//}

+ 5 - 0
services/sun_code.go

@@ -21,6 +21,11 @@ type SunCodeReq struct {
 
 // PcCreateAndUploadSunCode 生成太阳码并上传OSS
 func PcCreateAndUploadSunCode(scene, page string) (imgUrl string, err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("PcCreateAndUploadSunCode Err:" + err.Error())
+		}
+	}()
 	if page == "" {
 		err = errors.New("page不能为空")
 		return