audio:isPlaying() returns false for both pause and stop

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
JJSax
Prole
Posts: 47
Joined: Fri Apr 04, 2014 3:59 am

audio:isPlaying() returns false for both pause and stop

Post by JJSax »

I understand that the audio source:isPlaying() will only return true if it's playing and that seems to be intended. Is there a function that I'm not seeing that will only return true/false only if it's stopped? or return if it's paused? I just don't want to treat them the same way in my code. It seems like they were separated at one point but now both are under source:isPlaying()
User avatar
zorg
Party member
Posts: 3449
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: audio:isPlaying() returns false for both pause and stop

Post by zorg »

That decision was to simplify the internal state.

What you can do is to also check with source:tell() whether the audio is exactly at the 0 playback position, or in other words, at the start.
If it is, then either:
- It was never started (and/or seeked into), or
- It was stopped, which is basically :pause() + :rewind(), which in turn is just :seek(0).

Since they are logically the same, you can treat them as such, but if you -really- need to separate them as state, and not just for button's sake, then:

Code: Select all

if not source:isPlaying() then
    if source:tell() == 0 then
        return 'stopped'
    else
        return 'paused'
    end
else
    return 'playing'
end
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
JJSax
Prole
Posts: 47
Joined: Fri Apr 04, 2014 3:59 am

Re: audio:isPlaying() returns false for both pause and stop

Post by JJSax »

zorg wrote: Fri Jul 26, 2019 8:01 pm That decision was to simplify the internal state.

What you can do is to also check with source:tell() whether the audio is exactly at the 0 playback position, or in other words, at the start.
If it is, then either:
- It was never started (and/or seeked into), or
- It was stopped, which is basically :pause() + :rewind(), which in turn is just :seek(0).
snip
Beautiful! And thanks for the explanation of why they made the change. It makes sense and I learn way better when I know the "why". I've tested it and it works perfectly. Thank you!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests