Hi. I just wanted to ask if anyone could help me regarding this sketchup UI module. im new to this programming so please bare with my technical difficulties.
I am trying to play a sound in Skethup. when i enter the code in ruby console, it returns nil.
here is my code:
UI.play_sound (“Plugins/polaroid.wav”)
I have already put a polaroid.wav file in my plugin directory of Sketchup but it still dont play a sound.
You need to pass the full file-path to the method.
e.g. UI.play_sound(File.join(Sketchup.find_support_file(‘Plugins’), ‘polaroid.wav’))
Rather than having various files ‘lose’ in the Plugins folder I recommend that you make a subfolder for your extension which contains any files it needs, you can then add that into the file-path…
Also you could check the file exists before trying to play it.
You didn’t form the soundpath as I suggested.
Find the Plugins folder then use the File tools to add the wav file onto it so you then have a valid file-path.
The way it is now you’re trying to pass 2 arguments to find_support_file - it only expects 1, so the wav file part is ignored !
UI.play_sound(File.join(Sketchup.find_support_file(‘Plugins’), ‘james’, ‘polaroid.wav’))
You can’t mess with the find_support_file’s path.
Find it then add the subfolder and wav name and it should work…
Because you don’t have file-types set to be displayed we are guessing it’s a .wav file !!!
I tried using the same syntax in returning string path to the toolbar’s icon pic. to find if it works. Surprisingly, it works. I dont know why it dont works in playing a sound. The png file for the icon’s pic is in the same folder as the wav file for playing the sound.
here is the code:
toolbar = UI::Toolbar.new “Test”
cmd = UI::Command.new(“Test”){
UI.messagebox(“Gwapo Si James”)
UI.play_sound(File.join(Sketchup.find_support_file(‘Plugins’), ‘james’, ‘polaroid.wav’))
the toolbar’s icon displays the png file, written in the code, as it intended. But no sound was played, even entering the single line for playing the sound in ruby console.
Thanks for advices. It seems that the audio file is the problem. I tried various softwares for wav files conversions and only few of those output could be use to allow UI.play_sound to execute.