hendriks73 / ffsampledsp

FFmpeg based service provider for javax.sound.sampled.
GNU Lesser General Public License v2.1
24 stars 5 forks source link

Allow retrieving current playback position #9

Closed mvmn closed 3 years ago

mvmn commented 3 years ago

Allow retrieving current playback position from FFAudioInputStream

mvmn commented 3 years ago

Nevermind: turns out it's not helpful at all in detecting current playback position since framePos is not actually updated.

hendriks73 commented 3 years ago

The best way, IMHO, to get the current playback position is to call dataLine.getMicrosecondPosition() - assuming you are playing your AudioInputStream with some sort of DataLine.

If that's not an option, I'd recommend keeping track of how many frames you have already read form the AudioInputStream and convert that to seconds. Unfortunately, because of buffer sizes, that will always be a little chunky.

mvmn commented 3 years ago

Current dirty hack I've made is to read framePos from a PCM_SIGNED AudioInputStream stream that is converted from original AudioInputStream - via reflection :-(

As for dataLine.getMicrosecondPosition() - not sure how this will work with a seek.

hendriks73 commented 3 years ago

As for dataLine.getMicrosecondPosition() - not sure how this will work with a seek.

You'd have to remember your current offset, whenever you seek.