Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ PlaySound

PlaySound

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Dzbanek   (4 posts)  Bio
Date Wed 16 Jul 2014 04:59 AM (UTC)
Message
Hello

How can I play a number of sounds one after another? I would like to hear them one after one.
Something like:

function test()
PlayMySound("1.wav")
PlayMySound("2.wav")
PlayMySound("3.wav")
end

Of course when I just use PlaySound I will hear all of them at the same time.

I thought about using timers and checking if sound is playing in for example buffer 1 to play next one and setting the name of it in the variable but it won't work for more than 2 sounds. Forgive me my poor knowledge.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 16 Jul 2014 05:51 AM (UTC)
Message
You should be able to use GetSoundStatus to see if a sound has finished playing and then move onto playing another one. I don't see why that would not work for more than two sounds.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Dzbanek   (4 posts)  Bio
Date Reply #2 on Wed 16 Jul 2014 06:00 AM (UTC)
Message
function test()
PlayMySound("1.wav")
PlayMySound("2.wav")
PlayMySound("3.wav")
end

function PlayMySound(filename)
while GetSoundStatus(1) > 0 then
end
PlaySound (1, filename, false, 0, 0)
end

In this example test plays 3 files but in real example different function can play a sound. I'm not sure it that while loop won't hang my whole plugin?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 16 Jul 2014 06:06 AM (UTC)

Amended on Wed 16 Jul 2014 06:07 AM (UTC) by Nick Gammon

Message
This works, I just tested it:


require "wait"

function PlayOneSound (name)
  while GetSoundStatus (1) > 0 do
    wait.time (0.1)
  end -- while
  PlaySound (1, name)
end -- PlayOneSound 

function soundTest ()

  wait.make ( function ()

    PlayOneSound ("1.wav")
    PlayOneSound ("2.wav")
    PlayOneSound ("3.wav")

  end )  -- end of wait.make

end -- soundTest

soundTest ()


Using the "wait" module like this stops the client from hanging while it plays the sounds, potentially for quite a few seconds.

See: http://gammon.com.au/modules

In particular:

http://www.gammon.com.au/forum/?id=4956

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Dzbanek   (4 posts)  Bio
Date Reply #4 on Wed 16 Jul 2014 06:14 AM (UTC)
Message
Umm right. But I see I need to pass PlayOneSound to the wait. Not sure how I can do that in the following example:

function a()
PlayOneSound ("1.wav")
end

function b()
PlayOneSound ("2.wav")
end

function c()
PlayOneSound ("3.wav")
end

So, basically there are different functions playing different sounds. Any further help, please? Forgive me my lack of knowledge, trying to learn:)
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Wed 16 Jul 2014 06:23 AM (UTC)
Message
Just move the wait inside PlayOneSound like this:


require "wait"

function PlayOneSound (name)
  wait.make ( function ()
    while GetSoundStatus (1) > 0 do
      wait.time (0.1)
    end -- while
    PlaySound (1, name)
  end )  -- end of wait.make

end -- PlayOneSound 

PlayOneSound ("1.wav")
PlayOneSound ("2.wav")
PlayOneSound ("3.wav")


Now you can call PlayOneSound whenever you feel like it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Dzbanek   (4 posts)  Bio
Date Reply #6 on Wed 16 Jul 2014 06:29 AM (UTC)
Message
Thank you very much! It works great:)
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


23,435 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.