mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-27 04:08:53 +01:00
audio: Bug fix: there could be chunks after 'data' chunk
This commit is contained in:
parent
e22561c292
commit
ffbe450c3f
@ -70,8 +70,7 @@ func (p *players) Read(b []byte) (int, error) {
|
||||
closed := []*Player{}
|
||||
l := len(b)
|
||||
for p := range p.players {
|
||||
err := p.readToBuffer(l)
|
||||
if err == io.EOF {
|
||||
if err := p.readToBuffer(l); err == io.EOF {
|
||||
closed = append(closed, p)
|
||||
} else if err != nil {
|
||||
return 0, err
|
||||
|
@ -28,19 +28,30 @@ type Stream struct {
|
||||
src audio.ReadSeekCloser
|
||||
headerSize int64
|
||||
dataSize int64
|
||||
remaining int64
|
||||
}
|
||||
|
||||
// Read is implementation of io.Reader's Read.
|
||||
func (s *Stream) Read(p []byte) (int, error) {
|
||||
return s.src.Read(p)
|
||||
if s.remaining <= 0 {
|
||||
return 0, io.EOF
|
||||
}
|
||||
if s.remaining < int64(len(p)) {
|
||||
p = p[0:s.remaining]
|
||||
}
|
||||
n, err := s.src.Read(p)
|
||||
s.remaining -= int64(n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Seek is implementation of io.Seeker's Seek.
|
||||
func (s *Stream) Seek(offset int64, whence int) (int64, error) {
|
||||
if whence == 0 {
|
||||
if whence == io.SeekStart {
|
||||
offset += s.headerSize
|
||||
}
|
||||
return s.src.Seek(offset, whence)
|
||||
n, err := s.src.Seek(offset, whence)
|
||||
s.remaining = s.dataSize - (n - s.headerSize)
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Read is implementation of io.Closer's Close.
|
||||
@ -139,6 +150,7 @@ chunks:
|
||||
src: src,
|
||||
headerSize: headerSize,
|
||||
dataSize: dataSize,
|
||||
remaining: dataSize,
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user