locked
Custom Sounds in Small Basic RRS feed

  • Question

  • Hey,

    I tried to use a custom click sound in small basic because I didn't like the classic one. I don't find any solution. Even if I use the classic small basic click sound, there will be a moment where I have to use a custom sound. Can anyone help me?

    Edit: If possible, post a solution which helps me with the custom sound problem and not the click sound problem
    • Edited by box57 Friday, July 13, 2018 8:08 PM
    Friday, July 13, 2018 8:07 PM

Answers

  • This is a sound I uploaded for a game a while ago and works for me.  Note I said set its extension correctly by moving it.

    url = "http://litdev.co.uk/curling/sweep.wma"
    tmp = Network.DownloadFile(url)
    mySound = Program.Directory+"\mySound.wma"
    File.CopyFile(tmp,mySound)
    File.DeleteFile(tmp)
    Sound.Play(mySound)
    TextWindow.Pause()

    In your case this works for me

    url = "https://www.dropbox.com/s/bq3zcinz7hf60vw/clickmp3.mp3?dl=1"
    tmp = Network.DownloadFile(url)
    mySound = Program.Directory+"\mySound.mp3"
    File.CopyFile(tmp,mySound)
    File.DeleteFile(tmp)
    Sound.Play(mySound)
    TextWindow.Pause()



    • Edited by litdev Saturday, July 14, 2018 9:28 PM
    • Marked as answer by box57 Saturday, July 14, 2018 9:41 PM
    Saturday, July 14, 2018 9:13 PM
  • perhaps that is permissions - try the version I edit with your file

    you cannot upload to my web server



    url = "https://www.dropbox.com/s/bq3zcinz7hf60vw/clickmp3.mp3?dl=1"
    tmp = Network.DownloadFile(url)
    mySound = Program.Directory+"\mySound.mp3"
    File.CopyFile(tmp,mySound)
    File.DeleteFile(tmp)
    Sound.Play(mySound)
    TextWindow.Pause()
    • Edited by litdev Saturday, July 14, 2018 9:41 PM
    • Marked as answer by box57 Saturday, July 14, 2018 9:42 PM
    Saturday, July 14, 2018 9:39 PM
  • Couple suggestions:

    1] call sound.stop before any sound.play to reset mediaplayer to sound start.

    2] consider sound.playandwait to ensure sound completes before continuing - depending on your needs

      For n = 1 To i
        Sound.Stop(Program.Directory + "\clickmp3.mp3")
        Sound.PlayAndWait(Program.Directory + "\clickmp3.mp3")
        TextWindow.WriteLine(Program.Directory + "\clickmp3.mp3")
        Program.Delay(wait)
      endfor
    

    • Marked as answer by box57 Sunday, July 15, 2018 11:38 AM
    Sunday, July 15, 2018 9:22 AM

All replies

  • Have you tried Sound.Play with your own wav or mp3 sound effect.
    Saturday, July 14, 2018 6:06 PM
  • Yes I tried. If I use the file from my PC it works. But I need to upload the sound file because not everyone owns it.


    Saturday, July 14, 2018 8:29 PM
  • So one soltion is to upload the file somewhere and get your program to download it and then use it.  This can be done with Network.DownloadFile, you then should move the file (copy and delete) and set its extension to wma or mp3 in local folder and then use it.

    First step is to get somewhere on the web to upload your sound resource file - like a free web server.


    • Edited by litdev Saturday, July 14, 2018 8:52 PM
    Saturday, July 14, 2018 8:42 PM
  • I uploaded the sound file with dropbox and tried this:

    soundfiledl=Network.DownloadFile("https://www.dropbox.com/s/bq3zcinz7hf60vw/clickmp3.mp3?dl=1")

    Sound.Play(soundfiledl)

    But it isnt working. Even with a program delay between the download and the sound play won't make it work.

    Any other ideas? xD

    Edit: why do i have to set its extension to wma or mp3 if I paste the copied original sound file in the local folder it's still a mp3 file
    • Edited by box57 Saturday, July 14, 2018 9:15 PM
    Saturday, July 14, 2018 9:05 PM
  • This is a sound I uploaded for a game a while ago and works for me.  Note I said set its extension correctly by moving it.

    url = "http://litdev.co.uk/curling/sweep.wma"
    tmp = Network.DownloadFile(url)
    mySound = Program.Directory+"\mySound.wma"
    File.CopyFile(tmp,mySound)
    File.DeleteFile(tmp)
    Sound.Play(mySound)
    TextWindow.Pause()

    In your case this works for me

    url = "https://www.dropbox.com/s/bq3zcinz7hf60vw/clickmp3.mp3?dl=1"
    tmp = Network.DownloadFile(url)
    mySound = Program.Directory+"\mySound.mp3"
    File.CopyFile(tmp,mySound)
    File.DeleteFile(tmp)
    Sound.Play(mySound)
    TextWindow.Pause()



    • Edited by litdev Saturday, July 14, 2018 9:28 PM
    • Marked as answer by box57 Saturday, July 14, 2018 9:41 PM
    Saturday, July 14, 2018 9:13 PM
  • That program worked really fine. The problem is, I cant upload my file because if I press "return to main page" only the link changes a bit but the button is still there.

    If i enter "litdev.co.uk/curling/" this happens:

    Forbidden

    You don't have permission to access /curling/ on this server.

    Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

    And if I enter "litdev.co.uk" I dont know where to upload the file.



    • Edited by box57 Saturday, July 14, 2018 9:33 PM
    Saturday, July 14, 2018 9:32 PM
  • perhaps that is permissions - try the version I edit with your file

    you cannot upload to my web server



    url = "https://www.dropbox.com/s/bq3zcinz7hf60vw/clickmp3.mp3?dl=1"
    tmp = Network.DownloadFile(url)
    mySound = Program.Directory+"\mySound.mp3"
    File.CopyFile(tmp,mySound)
    File.DeleteFile(tmp)
    Sound.Play(mySound)
    TextWindow.Pause()
    • Edited by litdev Saturday, July 14, 2018 9:41 PM
    • Marked as answer by box57 Saturday, July 14, 2018 9:42 PM
    Saturday, July 14, 2018 9:39 PM
  • ahhhh didnt see it XD
    Saturday, July 14, 2018 9:40 PM
  • you helped me out so much! a big thanks to you :)
    Saturday, July 14, 2018 9:41 PM
  • Are you sure that it works with clickmp3.mp3.
    This is a very short soundfile and I have to repeat the Play-Button of Mediaplayer in short intervalls < 500ms.

    Above 500ms I hear nothing.

    Programmatically with Small Basic there is no success:

    i=1
    While i > 0 
      TextWindow.WriteLine("")
      TextWindow.Write("Number of clicks: ")
      i = TextWindow.ReadNumber()
      If i <= 0 Then
        Goto End
      EndIf
      TextWindow.WriteLine("")
      TextWindow.Write("Distance [ms]: ")
      wait = TextWindow.ReadNumber()
      For n = 1 To i
        Sound.Play(Program.Directory + "\clickmp3.mp3")
        TextWindow.WriteLine(Program.Directory + "\clickmp3.mp3")
        Program.Delay(wait)
      endfor
    EndWhile
    End:
    Program.End()

    Saturday, July 14, 2018 10:30 PM
  • Couple suggestions:

    1] call sound.stop before any sound.play to reset mediaplayer to sound start.

    2] consider sound.playandwait to ensure sound completes before continuing - depending on your needs

      For n = 1 To i
        Sound.Stop(Program.Directory + "\clickmp3.mp3")
        Sound.PlayAndWait(Program.Directory + "\clickmp3.mp3")
        TextWindow.WriteLine(Program.Directory + "\clickmp3.mp3")
        Program.Delay(wait)
      endfor
    

    • Marked as answer by box57 Sunday, July 15, 2018 11:38 AM
    Sunday, July 15, 2018 9:22 AM
  • Also no success with the improvements Sound.Stop()  & Sound.PlayAndWait().

    There are differences between clickmp3.mp3 and other short mp3's(i.e. blob.mp3 out of Solitaire-Game).

    A doubleclick on blob.mp3 starts the Windows-Mediaplayer and play directly the sound.

    A doubleclick on clickmp3.mp3 starts the Windows-Mediaplayer and play no sound. 
    The sound starts only after fast repeating the Play-Button.

    Surprisingly clickmp3.mp3 runs on the system of box57. He marked the suggestions as answer.
    My system is WIN7pro 64bit.


    Sunday, July 15, 2018 9:40 PM
  • @ backtothestart

    Hi,

    I can't see any problem with SB code I have.  Do you have a short SB sample I can run that shows an issue?  I'm not sure what sounds you are using that give a problem.

    Tuesday, July 17, 2018 7:09 PM
  • If  the sequence starts with "clickmp3.mp3" I hear nothing. 
    Only by beginning with "sweep.wma" I hear sometimes the plop.

    start:
    TextWindow.Write("clickmp3.mp3 first? [y]  :")
    inp = TextWindow.Read()
    If inp = "y" then
     ' clickmp3.mp3
     url = "https://www.dropbox.com/s/bq3zcinz7hf60vw/clickmp3.mp3?dl=1"
     tmp = Network.DownloadFile(url)
     myClick = Program.Directory+"\myClick.mp3"
     File.CopyFile(tmp,myClick)
     sound.Stop(myClick)
     Sound.PlayAndWait(myClick)
     Sound.Play(myClick)
    else ' sweep.wma
     url = "http://litdev.co.uk/curling/sweep.wma"
     tmp = Network.DownloadFile(url)
     mySound = Program.Directory+"\mySound.wma"
     File.CopyFile(tmp,mySound)
     sound.Stop(mySound)
     Sound.PlayAndWait(mySound)
     Sound.Play(mySound)
    EndIf
    ' clickmp3.mp3
    url = "https://www.dropbox.com/s/bq3zcinz7hf60vw/clickmp3.mp3?dl=1"
    tmp = Network.DownloadFile(url)
    myClick = Program.Directory+"\myClick.mp3"
    File.CopyFile(tmp,myClick)
    sound.Stop(myClick)
    Sound.PlayAndWait(myClick)
     Sound.Play(myClick)
    Goto start
    

     
    Tuesday, July 17, 2018 9:06 PM
  • Mmm, it works as expected for me, only suggestion is to use sound.Stop before every call to Play or PlayAndWait. 

    It does take a bit of time to download (maybe 1 sec or so) and do the copying, so perhaps a small Program.Delay, say 100 ms after the FIle.Copy to make sure it is all done, but I don't need this on my WIn 10 PC?

    Wednesday, July 18, 2018 6:04 PM
  • Whats about by starting the Windows Media Player about doubleclick on the local MP3-Files.

    If "sweep.wma" and "clickmp3.mp3" have the same starting behaviour and "clickmp3.mp3" runs directly, then the reason is my WIN7-Enviroment.

    Litdev, please try it on your WIN10 PC. Thank you. 

    Wednesday, July 18, 2018 6:52 PM
  • H,

    Using Windows Media Player, both the click.mp3 and sweep.wma files play well.

    Wednesday, July 18, 2018 7:59 PM
  • Thanks for support,

    I will no longer search.

    Last Info: clickmp3.mp3 is ever played, but the sound volume is too low.
                   Only in combination with other MP3s or by fast repeating the Play-Button the loudness is normal.

    Possibly fading  or autovolume ?

    Wednesday, July 18, 2018 9:32 PM