1

Been trying some code in c++ again (coming from another language) which was long missed and stumbled upon updating a game. The question is my wxSound code can't seemed to work with my wxWidget based game. Here is my code:

    wxSound *mySound;
    mySound = new wxSound(); 
    mySound->Create(_T("explosion.wav"), false);
    mySound->Play( wxSOUND_ASYNC );

Build log says no errors

     /bin/sh -c '/usr/bin/make -j4 -e -f  Makefile'
    ----------Building project:...
    ...
    ...
    ====0 errors, 0 warnings====

I'm new to wxWidgets, is there something missing? I'm running wxWidget 3.1.5 on Ubuntu 20.04 and CodeLite.

  • `mySound->Play(false)` Can you please update the post with the wxWidgets version you are using? Also, https://docs.wxwidgets.org/3.0/classwx_sound.html#aca197e390cb89d6654bd3b368afbc681 doesn't have any method signature for `Play` containing boolean arguments. – kiner_shah Nov 05 '21 at 07:44
  • 1
    You are not doing any error checking; the problem could be as simple as explosion.wav not being found in the path you expected. That would not be detected at build time, obviously. – Lauri Nurmi Nov 05 '21 at 09:13
  • tnx @kiner_shah for indicating the needed wxWidget version (3.1.5) and the Play(false) call. I've edited my code to call 'mySound->Play( wxSOUND_ASYNC );' and then 'mySound->Play();' instead, but still didn't play the wav file. Stil No errors were put in the build log. – Archimedes Abug Nov 05 '21 at 09:47
  • I agree with @LauriNurmi, you need to check if `Create()` and `Play()` were successful. – kiner_shah Nov 05 '21 at 09:52
  • Hi @LauriNurmi! explosion.wav was originally located in the Debug folder, thinking that it would be easy for the program file to locate the said file. Now I've tried inputing the complete file path in the function call Create(). Still having no luck. Also tried editing the 'Project Settings>Global Settings>Additional Search Path' & 'Project Settings>Resources>Additional Search Path'. Inputed the absolute file path but still the same result. need your help on this, maybe I missed a specific project setting? – Archimedes Abug Nov 05 '21 at 10:28
  • Thank you very much guys. I also added if-else statements on both Create() and Play() functions but both functions returned true. Also added some Exception Handling but didn't throw any exception. – Archimedes Abug Nov 05 '21 at 11:53
  • The code now looks like this: ' wxSound *mySound; mySound = new wxSound(); try{ if(mySound->Create(_T("/absolute/file/path/Debug/explosion.wav"), false)) std::cout<<"Create was successful\n"; else std::cout<<"Create was not successful\n"; if(!mySound->Play(wxSOUND_ASYNC)) std::cout<<"Play was not successful\n"; else std::cout<<"Play was successful\n"; } catch(...){ std::cout<<"Exception Thrown\n"; }' will look on this even further though – Archimedes Abug Nov 05 '21 at 12:02
  • @archimedesabug, what platform are you running it on? Can you try debugging and see what happens inside those functions? – Igor Nov 05 '21 at 12:44

0 Answers0