how to tell if audio is playing or paused

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

how to tell if audio is playing or paused

Post 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
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

Re: how to tell if audio is playing or paused

Post by randy0428 »

Nevermind. I found the source:isPlaying() function.
Sorry I didn't look more thoroughly before I posted.
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

Re: how to tell if audio is playing or paused

Post 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
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: how to tell if audio is playing or paused

Post by xNick1 »

Would you provide us a .love file?
I could try to help you that way
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

Re: how to tell if audio is playing or paused

Post by randy0428 »

The file is attached.
The code in my post starts on line 66 of the jogar.lua file.
Attachments
exemplo.love
(3.96 MiB) Downloaded 202 times
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: how to tell if audio is playing or paused

Post 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
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

Re: how to tell if audio is playing or paused

Post 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?
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

Re: how to tell if audio is playing or paused

Post by randy0428 »

Actually, I just tried it on a Windows 10 machine and it worked. Any ideas why it won't work on Linux?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest