oto icon indicating copy to clipboard operation
oto copied to clipboard

oto: add a function to get the player's current position

Open mark-summerfield opened this issue 2 years ago • 5 comments

I am trying to write a music player using oto. I know how long a track is based on the number of samples and the sample rate. However, during playback I want to be able to show progress, for which a Player.Position() int64 is needed.

mark-summerfield avatar Nov 25 '23 08:11 mark-summerfield

You can use Seek(0, io.SeekCurrent)

hajimehoshi avatar Nov 25 '23 12:11 hajimehoshi

I tried it but it doesn't work inside the isPlaying loop. Try running oaplay with an ogg audio file, e.g., go run . /path/to/track.ogg

mark-summerfield avatar Nov 25 '23 12:11 mark-summerfield

https://github.com/hajimehoshi/ebiten/blob/6f5fab47aa8780ec69d4687588a121aae54139de/audio/player.go#L253

Ebitengine already does that. You would have to consider buffer size actually.

EDIT: Ebitengine manages its position by itself. In theory you can do the same thing, but I admit this might be troublesome.

hajimehoshi avatar Nov 25 '23 12:11 hajimehoshi

I've worked around it by capturing the duration and start time and using time.Since() to give me the position during IsPlaying.

mark-summerfield avatar Nov 25 '23 13:11 mark-summerfield

Let me reopen this. I might add Position later.

hajimehoshi avatar Nov 25 '23 13:11 hajimehoshi