mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 20:42:07 +01:00
audio/mp3: Force context switch when decoding
This commit is contained in:
parent
18c6890d96
commit
7b1f501bd7
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/gopherjs/gopherjs/js"
|
"github.com/gopherjs/gopherjs/js"
|
||||||
"github.com/hajimehoshi/ebiten/audio"
|
"github.com/hajimehoshi/ebiten/audio"
|
||||||
@ -96,7 +97,7 @@ func (s *Stream) Size() int64 {
|
|||||||
// seekNextFrame also returns true when seeking is successful, or false otherwise.
|
// seekNextFrame also returns true when seeking is successful, or false otherwise.
|
||||||
//
|
//
|
||||||
// Seeking is necessary when decoding fails. Safari's MP3 decoder can't treat IDs well (#438).
|
// Seeking is necessary when decoding fails. Safari's MP3 decoder can't treat IDs well (#438).
|
||||||
func seekNextFrame(buf []uint8) ([]uint8, bool) {
|
func seekNextFrame(buf []byte) ([]byte, bool) {
|
||||||
// TODO: Need to skip tags explicitly? (hajimehoshi/go-mp3#9)
|
// TODO: Need to skip tags explicitly? (hajimehoshi/go-mp3#9)
|
||||||
|
|
||||||
if len(buf) < 1 {
|
if len(buf) < 1 {
|
||||||
@ -156,7 +157,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func decode(context *audio.Context, buf []uint8) (*Stream, error) {
|
func decode(context *audio.Context, buf []byte) (*Stream, error) {
|
||||||
if offlineAudioContextClass == nil {
|
if offlineAudioContextClass == nil {
|
||||||
return nil, errors.New("audio/mp3: OfflineAudioContext is not available")
|
return nil, errors.New("audio/mp3: OfflineAudioContext is not available")
|
||||||
}
|
}
|
||||||
@ -191,6 +192,10 @@ func decode(context *audio.Context, buf []uint8) (*Stream, error) {
|
|||||||
}
|
}
|
||||||
close(ch)
|
close(ch)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// GopherJS's bug? Without Gosched(), receiving might block forever.
|
||||||
|
runtime.Gosched()
|
||||||
|
|
||||||
if err := <-ch; err != nil {
|
if err := <-ch; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user