diff --git a/README.md b/README.md index 1f9b99120..438fdd13e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Note: Gamepad is not available on Safari/Android/iOS. Keyboard is not available ## Features -* 2D Graphics (Geometry/Color matrix transformation, Various composition modes, Offscreen rendering) +* 2D Graphics (Geometry/Color matrix transformation, Various composition modes, Offscreen rendering, Fullscreen) * Input (Mouse, Keyboard, Gamepads, Touches) * Audio (MP3, Ogg/Vorbis, WAV, PCM) diff --git a/_docs/index.tmpl.html b/_docs/index.tmpl.html index 8166d2693..0bfedac1d 100644 --- a/_docs/index.tmpl.html +++ b/_docs/index.tmpl.html @@ -47,7 +47,7 @@

Features

2D Graphics
-
Geometry/Color matrix transformation, Various composition modes, Offscreen rendering
+
Geometry/Color matrix transformation, Various composition modes, Offscreen rendering, Fullscreen
Input
Mouse, Keyboard, Gamepads, Touches
Audio
diff --git a/docs/examples/_resources/audio/classic.mp3 b/docs/examples/_resources/audio/classic.mp3 new file mode 100644 index 000000000..c6fc6207f Binary files /dev/null and b/docs/examples/_resources/audio/classic.mp3 differ diff --git a/docs/examples/_resources/audio/license.md b/docs/examples/_resources/audio/license.md index 49e149283..e2ae72a4f 100644 --- a/docs/examples/_resources/audio/license.md +++ b/docs/examples/_resources/audio/license.md @@ -1,5 +1,14 @@ # License +## classic.mp3 + +``` +https://musopen.org/music/466/johann-sebastian-bach/air-on-the-g-string-from-orchestral-suite-no-3-bwv-1068/ + +Air on the G String (from Orchestral Suite no. 3, BWV 1068) +Public Domain +``` + ## jab.wav ``` @@ -17,13 +26,6 @@ http://mart.kitunebi.com/music_act.html Harpie's Feather (ハルピュイアの羽) by Napi ``` -## game2.mp3 - -``` -http://mart.kitunebi.com/music_act.html - -ノアの羽舟 by Napi -``` ## ragtime.ogg diff --git a/docs/examples/audio.html b/docs/examples/audio.html index 5c957d860..c90d997a7 100644 --- a/docs/examples/audio.html +++ b/docs/examples/audio.html @@ -38,7 +38,7 @@ import ( "github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten/audio" - "github.com/hajimehoshi/ebiten/audio/vorbis" + "github.com/hajimehoshi/ebiten/audio/mp3" "github.com/hajimehoshi/ebiten/audio/wav" "github.com/hajimehoshi/ebiten/ebitenutil" ) @@ -47,7 +47,7 @@ const ( screenWidth = 320 screenHeight = 240 - // This sample rate doesn't match with wav/ogg's sample rate, + // This sample rate doesn't match with wav/mp3's sample rate, // but decoders adjust them. sampleRate = 48000 ) @@ -101,8 +101,8 @@ type Player struct { input *Input audioContext *audio.Context audioPlayer *audio.Player + current time.Duration total time.Duration - seekedCh chan error seBytes []uint8 seCh chan []uint8 volume128 int @@ -126,11 +126,11 @@ func NewPlayer(audioContext *audio.Context) (*Player, error) { if err != nil { return nil, err } - oggF, err := ebitenutil.OpenFile("_resources/audio/ragtime.ogg") + mp3F, err := ebitenutil.OpenFile("_resources/audio/classic.mp3") if err != nil { return nil, err } - s, err := vorbis.Decode(audioContext, oggF) + s, err := mp3.Decode(audioContext, mp3F) if err != nil { return nil, err } @@ -149,6 +149,9 @@ func NewPlayer(audioContext *audio.Context) (*Player, error) { volume128: 128, seCh: make(chan []uint8), } + if player.total == 0 { + player.total = 1 + } player.audioPlayer.Play() go func() { s, err := wav.Decode(audioContext, wavF) @@ -172,14 +175,11 @@ func (p *Player) update() error { case p.seBytes = <-p.seCh: close(p.seCh) p.seCh = nil - case err := <-p.seekedCh: - if err != nil { - return err - } - close(p.seekedCh) - p.seekedCh = nil default: } + if p.audioPlayer.IsPlaying() { + p.current = p.audioPlayer.Current() + } p.updateBar() p.updatePlayPause() p.updateSE() @@ -229,9 +229,6 @@ func (p *Player) updatePlayPause() { } func (p *Player) updateBar() { - if p.seekedCh != nil { - return - } if !p.input.isMouseButtonTriggered(ebiten.MouseButtonLeft) { return } @@ -246,10 +243,8 @@ func (p *Player) updateBar() { return } pos := time.Duration(x-bx) * p.total / time.Duration(bw) - p.seekedCh = make(chan error, 1) - go func() { - p.seekedCh <- p.audioPlayer.Seek(pos) - }() + p.current = pos + p.audioPlayer.Seek(pos) } func (p *Player) close() error { @@ -262,11 +257,9 @@ func (p *Player) draw(screen *ebiten.Image) { op.GeoM.Translate(float64(x), float64(y)) screen.DrawImage(playerBarImage, op) currentTimeStr := "00:00" - c := p.audioPlayer.Current() - prev := p.previousPos - p.previousPos = c // Current Time + c := p.current m := (c / time.Minute) % 100 s := (c / time.Second) % 60 currentTimeStr = fmt.Sprintf("%02d:%02d", m, s) @@ -284,7 +277,10 @@ Press S to toggle Play/Pause Press P to play SE Press Z or X to change volume of the music %s`, ebiten.CurrentFPS(), currentTimeStr) - if p.audioPlayer.IsPlaying() && prev == c { + current := p.audioPlayer.Current() + prev := p.previousPos + p.previousPos = p.audioPlayer.Current() + if p.audioPlayer.IsPlaying() && prev == current { msg += "\nLoading..." } ebitenutil.DebugPrint(screen, msg) diff --git a/docs/index.html b/docs/index.html index 979ad845b..5864a5f09 100644 --- a/docs/index.html +++ b/docs/index.html @@ -47,7 +47,7 @@

Features

2D Graphics
-
Geometry/Color matrix transformation, Various composition modes, Offscreen rendering
+
Geometry/Color matrix transformation, Various composition modes, Offscreen rendering, Fullscreen
Input
Mouse, Keyboard, Gamepads, Touches
Audio