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 » Fri Feb 10, 2017 9:30 pm

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 » Fri Feb 10, 2017 9:43 pm

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 » Sat Jul 15, 2017 2:29 pm

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: 265
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: how to tell if audio is playing or paused

Post by xNick1 » Sat Jul 15, 2017 2:46 pm

Would you provide us a .love file?
I could try to help you that way
Currently working on a lucid dreaming adventure called Aarstider: http://bit.ly/2mXmgPI

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 » Sat Jul 15, 2017 3:05 pm

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 42 times

User avatar
xNick1
Party member
Posts: 265
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: how to tell if audio is playing or paused

Post by xNick1 » Sun Jul 16, 2017 3:22 pm

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
Currently working on a lucid dreaming adventure called Aarstider: http://bit.ly/2mXmgPI

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 » Sun Jul 16, 2017 4:07 pm

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 » Sun Jul 16, 2017 4:16 pm

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: Google [Bot] and 3 guests