audio:isPlaying() returns false for both pause and stop
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
audio:isPlaying() returns false for both pause and stop
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()
- 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
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:
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 True 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.
Re: audio:isPlaying() returns false for both pause and stop
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!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
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests