www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Simple way to play sounds using D

reply Murilo <murilomiranda92 hotmail.com> writes:
Hi guys, I would like to play simple sounds but I want something 
easy to use, can you show me the simplest way to do that? Like a 
function that just loads a .wav and plays it.
Feb 05 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 5 February 2019 at 16:50:36 UTC, Murilo wrote:
 Hi guys, I would like to play simple sounds but I want 
 something easy to use, can you show me the simplest way to do 
 that? Like a function that just loads a .wav and plays it.
If you are on Windows, the OS has a nice function for little ones: https://docs.microsoft.com/en-us/previous-versions//dd743680(v=vs.85)#examples
Feb 05 2019
parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Tuesday, 5 February 2019 at 17:01:54 UTC, Adam D. Ruppe wrote:
 On Tuesday, 5 February 2019 at 16:50:36 UTC, Murilo wrote:
 Hi guys, I would like to play simple sounds but I want 
 something easy to use, can you show me the simplest way to do 
 that? Like a function that just loads a .wav and plays it.
If you are on Windows, the OS has a nice function for little ones: https://docs.microsoft.com/en-us/previous-versions//dd743680(v=vs.85)#examples
Hi, thanks for the reply. import std.stdio, core.sys.windows.mmsystem; void main() { PlaySound("shoot.wav", null, SND_FILENAME); } When I compile the code above the compiler says Error: linker exited with status 1 What should I do?
Feb 05 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 5 February 2019 at 17:09:10 UTC, Murilo wrote:
 When I compile the code above the compiler says Error: linker 
 exited with status 1
 What should I do?
It might have to be "shoot.wav"w, notice the w on the end. But I am guessing the main problem is not linking in the winmm lib and dll. It will probably work to add pragma(lib, "winmm"); to your file right after the import.
Feb 05 2019
parent Murilo <murilomiranda92 hotmail.com> writes:
On Tuesday, 5 February 2019 at 17:14:05 UTC, Adam D. Ruppe wrote:
 On Tuesday, 5 February 2019 at 17:09:10 UTC, Murilo wrote:
 When I compile the code above the compiler says Error: linker 
 exited with status 1
 What should I do?
It might have to be "shoot.wav"w, notice the w on the end. But I am guessing the main problem is not linking in the winmm lib and dll. It will probably work to add pragma(lib, "winmm"); to your file right after the import.
You were right :) No need for the w but it was necessary the pragma(lib, "winmm"); It worked! Thanks so much man, all the best to you.
Feb 05 2019