Page 1 of 1

how to tell if audio is playing or paused

Posted: Fri Feb 10, 2017 9:30 pm
by randy0428
Is there such a thing as love.audio.isPlaying (or something that would tell if the audio is playing) or love.audio.isPaused (or something that would tell if the audio is paused)?

I want to have a single play/pause button that toggles between playing and paused.

The code would be something like:

Code: Select all

function toggleAudio(audioClip)
   if love.audio.isPlaying then love.audio.pause( audioClip )
   elseif love.audio.isPaused then love.audio.play( audioClip )
   end
end

Re: how to tell if audio is playing or paused

Posted: Fri Feb 10, 2017 9:39 pm
by raidho36

Re: how to tell if audio is playing or paused

Posted: Fri Feb 10, 2017 9:43 pm
by randy0428
Nevermind. I found the source:isPlaying() function.
Sorry I didn't look more thoroughly before I posted.

Re: how to tell if audio is playing or paused

Posted: Sat Jul 15, 2017 2:29 pm
by randy0428
I'm having a problem with this. I have a button that I want to toggle the music on or off.
Below is the code I'm using.
The emMusicOn(x,y) determines if the mouse is on the button.
The button works to pause the music, but clicking it again DOESN'T unpause (resume) it.
I added the 4 print statements to see if the button is changing the play state. Apparently the play state is changing,
Each time I click the button, the prinout indicates both the playing and paused values switch.
But there's no audio coming through.
I have no idea what the problem is.

Note1: I tried using love.audio.play( audioFundo ) instead of love.audio.resume( audioFundo ) but it still didn't work.
Note2: There are two other buttons to control volume, but I'm not touching them and I don't see how they could be the problem.

Code: Select all

  mousereleased = function(x, y, button)
   --CLIQUES DO MOUSE
    if emMusicOn( x, y ) then
      print("playing =")
      print(audioFundo:isPlaying())
      print("paused =")
      print(audioFundo:isPaused())
      if audioFundo:isPlaying() then love.audio.pause( audioFundo )
        elseif audioFundo:isPaused() then love.audio.resume( audioFundo )
      end
    return
    end

Re: how to tell if audio is playing or paused

Posted: Sat Jul 15, 2017 2:46 pm
by xNick1
Would you provide us a .love file?
I could try to help you that way

Re: how to tell if audio is playing or paused

Posted: Sat Jul 15, 2017 3:05 pm
by randy0428
The file is attached.
The code in my post starts on line 66 of the jogar.lua file.

Re: how to tell if audio is playing or paused

Posted: Sun Jul 16, 2017 3:22 pm
by xNick1
randy0428 wrote:
Sat Jul 15, 2017 2:29 pm
The button works to pause the music, but clicking it again DOESN'T unpause (resume) it.
It works on my machine, it pauses and resumes correctly o.O

Re: how to tell if audio is playing or paused

Posted: Sun Jul 16, 2017 4:07 pm
by randy0428
That's very strange. I tried again (using the .love file I sent you) and it didn't work.
What OS did you try it on?
I'm using a machine with Antergos Linux (an Arch variant) and love version 0.10.2-1 is installed. Any ideas why it works for you but not me?

Re: how to tell if audio is playing or paused

Posted: Sun Jul 16, 2017 4:16 pm
by randy0428
Actually, I just tried it on a Windows 10 machine and it worked. Any ideas why it won't work on Linux?