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