mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
audio: rename Seek -> SetPosition and Current -> Position
Seek and Current are not removed but marked as deprecated. Closes #2698
This commit is contained in:
parent
b2be456af8
commit
fbea792fe4
@ -368,13 +368,20 @@ func (p *Player) Rewind() error {
|
|||||||
return p.p.Rewind()
|
return p.p.Rewind()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetPosition sets the position with the given offset.
|
||||||
|
//
|
||||||
|
// The passed source to NewPlayer must be io.Seeker, or SetPosition panics.
|
||||||
|
//
|
||||||
|
// SetPosition returns error when seeking the source stream returns an error.
|
||||||
|
func (p *Player) SetPosition(offset time.Duration) error {
|
||||||
|
return p.p.SetPosition(offset)
|
||||||
|
}
|
||||||
|
|
||||||
// Seek seeks the position with the given offset.
|
// Seek seeks the position with the given offset.
|
||||||
//
|
//
|
||||||
// The passed source to NewPlayer must be io.Seeker, or Seek panics.
|
// Deprecated: as of v2.6. Use SetPosition instead.
|
||||||
//
|
|
||||||
// Seek returns error when seeking the source stream returns error.
|
|
||||||
func (p *Player) Seek(offset time.Duration) error {
|
func (p *Player) Seek(offset time.Duration) error {
|
||||||
return p.p.Seek(offset)
|
return p.SetPosition(offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause pauses the playing.
|
// Pause pauses the playing.
|
||||||
@ -382,12 +389,19 @@ func (p *Player) Pause() {
|
|||||||
p.p.Pause()
|
p.p.Pause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Position returns the current position in time.
|
||||||
|
//
|
||||||
|
// As long as the player continues to play, Position's returning value is increased monotonically,
|
||||||
|
// even though the source stream loops and its position goes back.
|
||||||
|
func (p *Player) Position() time.Duration {
|
||||||
|
return p.p.Position()
|
||||||
|
}
|
||||||
|
|
||||||
// Current returns the current position in time.
|
// Current returns the current position in time.
|
||||||
//
|
//
|
||||||
// As long as the player continues to play, Current's returning value is increased monotonically,
|
// Deprecated: as of v2.6. Use Position instead.
|
||||||
// even though the source stream loops and its position goes back.
|
|
||||||
func (p *Player) Current() time.Duration {
|
func (p *Player) Current() time.Duration {
|
||||||
return p.p.Current()
|
return p.Position()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Volume returns the current volume of this player [0-1].
|
// Volume returns the current volume of this player [0-1].
|
||||||
|
@ -243,7 +243,7 @@ func (p *playerImpl) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) Current() time.Duration {
|
func (p *playerImpl) Position() time.Duration {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
if err := p.ensurePlayer(); err != nil {
|
if err := p.ensurePlayer(); err != nil {
|
||||||
@ -256,10 +256,10 @@ func (p *playerImpl) Current() time.Duration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) Rewind() error {
|
func (p *playerImpl) Rewind() error {
|
||||||
return p.Seek(0)
|
return p.SetPosition(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) Seek(offset time.Duration) error {
|
func (p *playerImpl) SetPosition(offset time.Duration) error {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ func (p *Player) update() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.audioPlayer.IsPlaying() {
|
if p.audioPlayer.IsPlaying() {
|
||||||
p.current = p.audioPlayer.Current()
|
p.current = p.audioPlayer.Position()
|
||||||
}
|
}
|
||||||
if err := p.seekBarIfNeeded(); err != nil {
|
if err := p.seekBarIfNeeded(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -327,7 +327,7 @@ func (p *Player) seekBarIfNeeded() error {
|
|||||||
}
|
}
|
||||||
pos := time.Duration(x-bx) * p.total / time.Duration(bw)
|
pos := time.Duration(x-bx) * p.total / time.Duration(bw)
|
||||||
p.current = pos
|
p.current = pos
|
||||||
if err := p.audioPlayer.Seek(pos); err != nil {
|
if err := p.audioPlayer.SetPosition(pos); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -73,9 +73,9 @@ func (g *Game) Update() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Draw(screen *ebiten.Image) {
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
pos := g.player.Current()
|
pos := g.player.Position()
|
||||||
if pos > 5*time.Second {
|
if pos > 5*time.Second {
|
||||||
pos = (g.player.Current()-5*time.Second)%(4*time.Second) + 5*time.Second
|
pos = (g.player.Position()-5*time.Second)%(4*time.Second) + 5*time.Second
|
||||||
}
|
}
|
||||||
msg := fmt.Sprintf(`TPS: %0.2f
|
msg := fmt.Sprintf(`TPS: %0.2f
|
||||||
This is an example using
|
This is an example using
|
||||||
|
@ -104,7 +104,7 @@ func (g *Game) Update() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Draw(screen *ebiten.Image) {
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
pos := g.player.Current()
|
pos := g.player.Position()
|
||||||
msg := fmt.Sprintf(`TPS: %0.2f
|
msg := fmt.Sprintf(`TPS: %0.2f
|
||||||
This is an example using
|
This is an example using
|
||||||
stereo audio panning.
|
stereo audio panning.
|
||||||
|
Loading…
Reference in New Issue
Block a user