mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: Refactoring: Use the underlying source's Seek in Read (reland)
This commit is contained in:
parent
b81736793d
commit
90f59aad7c
@ -83,11 +83,12 @@ func (i *InfiniteLoop) Read(b []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err == io.EOF || i.pos == i.length() {
|
if err == io.EOF || i.pos == i.length() {
|
||||||
pos, err := i.Seek(i.lstart, io.SeekStart)
|
// Ignore the new position returned by Seek since the source position might not be match with the position
|
||||||
if err != nil {
|
// managed by this.
|
||||||
|
if _, err := i.src.Seek(i.lstart, io.SeekStart); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i.pos = pos
|
i.pos = i.lstart
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
@ -110,7 +111,7 @@ func (i *InfiniteLoop) Seek(offset int64, whence int) (int64, error) {
|
|||||||
if next < 0 {
|
if next < 0 {
|
||||||
return 0, fmt.Errorf("audio: position must >= 0")
|
return 0, fmt.Errorf("audio: position must >= 0")
|
||||||
}
|
}
|
||||||
if next >= i.lstart {
|
if next > i.lstart {
|
||||||
next = ((next - i.lstart) % i.llength) + i.lstart
|
next = ((next - i.lstart) % i.llength) + i.lstart
|
||||||
}
|
}
|
||||||
// Ignore the new position returned by Seek since the source position might not be match with the position
|
// Ignore the new position returned by Seek since the source position might not be match with the position
|
||||||
|
Loading…
Reference in New Issue
Block a user