Skip to content

Commit

Permalink
fix(sdk): 当音频包内某个源文件被删除后, 在播放过程中不应该panic, 仅通过log记录对应的事件即可。(后续需要做进一步处理…
Browse files Browse the repository at this point in the history
…,如提示前端或是继续判断之后优先级的声效直到嵌入测试音的播放)

commit #51
  • Loading branch information
LuSrackhall committed Dec 26, 2024
1 parent 1e837c5 commit 0caa183
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions sdk/keySound/keySound.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,26 @@ func PlayKeySound(audioFilePath *AudioFilePath, cut *Cut) {
var ext string // 用于判断音频类型
if audioFilePath.Part != "" {
audioFile, err = os.Open(audioFilePath.Part)
if err != nil {
panic(err)
}
ext = strings.ToLower(filepath.Ext(audioFilePath.Part))
} else if audioFilePath.Global != "" {
audioFile, err = os.Open(audioFilePath.Global)
if err != nil {
panic(err)
}
ext = strings.ToLower(filepath.Ext(audioFilePath.Global))
} else {
audioFile, err = sounds.Open("sounds/" + audioFilePath.SS)
if err != nil {
panic(err)
}
ext = strings.ToLower(filepath.Ext(audioFilePath.SS))
}

if err != nil {
logger.Error("message", fmt.Sprintf("error: failed to open audio file: %v", err))
return
}
defer audioFile.Close()

// 对文件进行解码
audioStreamer, format, err := decodeAudioFile(audioFile, ext)
if err != nil {
panic(err)
logger.Error("message", fmt.Sprintf("error: failed to decode audio file: %v", err))
return
}
defer audioStreamer.Close()

Expand Down

0 comments on commit 0caa183

Please sign in to comment.