Compare commits
1 Commits
v1.0.2
...
v1.0.2-rc5
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d23c1704f |
@@ -39,17 +39,8 @@ func PlayWav(c context.Context, r io.Reader) {
|
|||||||
s := beep.Resample(4, format.SampleRate, DefaultSampleRate, streamer)
|
s := beep.Resample(4, format.SampleRate, DefaultSampleRate, streamer)
|
||||||
|
|
||||||
ctrl := &beep.Ctrl{Streamer: s}
|
ctrl := &beep.Ctrl{Streamer: s}
|
||||||
|
|
||||||
// 测试 Streamer 是否可以正常读取数据
|
|
||||||
testSamples := make([][2]float64, 10)
|
|
||||||
n, ok := s.Stream(testSamples)
|
|
||||||
zap.S().Debugf("测试读取 Resampler: 读取 %d 样本, ok=%v, 数据=%v", n, ok, testSamples[:n])
|
|
||||||
|
|
||||||
// 重置 streamer
|
|
||||||
s = beep.Resample(4, format.SampleRate, DefaultSampleRate, streamer)
|
|
||||||
ctrl.Streamer = s
|
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
speaker.Play(beep.Seq(ctrl, beep.Callback(func() {
|
speaker.Play(beep.Seq(ctrl, beep.Callback(func() {
|
||||||
zap.S().Debugln("音频播放完成")
|
zap.S().Debugln("音频播放完成")
|
||||||
close(done)
|
close(done)
|
||||||
@@ -79,9 +70,9 @@ func PlayWav(c context.Context, r io.Reader) {
|
|||||||
currentTime := float64(pos) / float64(format.SampleRate)
|
currentTime := float64(pos) / float64(format.SampleRate)
|
||||||
zap.S().Debugf("播放进度: %d/%d (%.1f%%), %.2f秒", pos, totalSamples, progress, currentTime)
|
zap.S().Debugf("播放进度: %d/%d (%.1f%%), %.2f秒", pos, totalSamples, progress, currentTime)
|
||||||
lastPos = pos
|
lastPos = pos
|
||||||
} else {
|
} else if lastPos > 0 {
|
||||||
zap.S().Debugf("播放停滞在位置: %d/%d, Streamer状态: %v",
|
// 只有在已经开始播放后才报告停滞
|
||||||
pos, totalSamples, ctrl.Streamer != nil)
|
zap.S().Debugf("播放停滞在位置: %d/%d", pos, totalSamples)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user