[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  PlaySound

PlaySound

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


Posted by Dzbanek   (4 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by Dzbanek   (4 posts)  [Biography] 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?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by Dzbanek   (4 posts)  [Biography] 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:)
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by Dzbanek   (4 posts)  [Biography] bio
Date Reply #6 on Wed 16 Jul 2014 06:29 AM (UTC)
Message
Thank you very much! It works great:)
[Go to top] 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.


15,087 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]