ofSoundPlayer get duration in

Is it possible to get duration of an ofSoundPlayer object? in milliseconds or seconds?
it would be great to have a similar check as ofVideoPlayer getIsMovieDone too

I personally do :

bool isSongDone(ofSoundPlayer* sPlayer){
    bool donePlaying = false;
    // 99% of the song is played
    if(object.getPosition() > 0.99)donePlaying = true;
    return donePlaying;

Although you do squish some 1% of the songs you are playing, but for me that’s good enough…,.


1 Like

Thank you @pierre_tardif00
my same approach but I was afraid some case .99 wasn’t trigger in a small sound file.

Here is a PR and discussion.


IIRC the duration is there but has not been exposed to the public api, it can be used tweaking the source but there is a simpler way. Just after loading the audio file do something like this:

        int durationMs = soundPlayer.getPositionMS();

For some reason I do not understand the position range for sound player (on Linux at least) seems to be 0.0 to 2.0 but it works.