Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mark-summerfield opened this issue Nov 25, 2023 · 5 comments
Open

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

mark-summerfield opened this issue Nov 25, 2023 · 5 comments
Milestone

Comments

@mark-summerfield
Copy link

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.

@hajimehoshi
Copy link
Member

You can use Seek(0, io.SeekCurrent)

@mark-summerfield
Copy link
Author

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

@hajimehoshi
Copy link
Member

hajimehoshi commented Nov 25, 2023

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 hajimehoshi changed the title Please add Player.Position() int64 oto: add a function to get the player's current position Nov 25, 2023
@hajimehoshi hajimehoshi added this to the v3.2.0 milestone Nov 25, 2023
@mark-summerfield
Copy link
Author

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

@hajimehoshi
Copy link
Member

Let me reopen this. I might add Position later.

@hajimehoshi hajimehoshi reopened this Nov 25, 2023
@hajimehoshi hajimehoshi modified the milestones: v3.3.0, v3.4.0 Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants