sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Sound Effecs in SketchUp (HELP)

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    31 貼文 6 Posters 6.5k 瀏覽 6 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • Dan RathbunD 離線
      Dan Rathbun
      最後由 編輯

      Well you would need require the js file where Audio IS defined, I would imagine.

      I'm not here much anymore.

      1 條回覆 最後回覆 回覆 引用 0
      • TIGT 離線
        TIG Moderator
        最後由 編輯

        OR perhaps something like
        snd=document.createElement('audio'); snd.setAttribute('src', 'zap1.wav'); snd.play();
        ?

        TIG

        1 條回覆 最後回覆 回覆 引用 0
        • D 離線
          driven
          最後由 編輯

          When run from Ruby Console the tests in the WebDialog , except the 'IE' BGSOUND tag work on a mac, obviously only single file, as written, and only with plugin for the java ones.

          wwhdlg = UI;;WebDialog.new("wot_works_here", true, "wwh", 1200, 641, 50, 50, true);
           wwhdlg.set_url "http://www.phon.ucl.ac.uk/home/mark/audio/play.htm"
           wwhdlg.show_modal 
           wwhdlg.navigation_buttons_enabled=true
          

          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 條回覆 最後回覆 回覆 引用 0
          • renderizaR 離線
            renderiza
            最後由 編輯

            @tig said:

            OR perhaps something like
            snd=document.createElement('audio'); snd.setAttribute('src', 'zap1.wav'); snd.play();
            ?

            Keep getting errors

            Error 'document' is undefined

            ...if I use;

            var snd=document.createElement('audio');
            var snd.setAttribute('src', 'zap1.wav');
            snd.play();

            it says;

            Error: Expected ';'


            @driven said:

            When run from Ruby Console the tests in the WebDialog , except the 'IE' BGSOUND tag work on a mac, obviously only single file, as written, and only with plugin for the java ones.

            wwhdlg = UI;;WebDialog.new("wot_works_here", true, "wwh", 1200, 641, 50, 50, true);
            >  wwhdlg.set_url "http://www.phon.ucl.ac.uk/home/mark/audio/play.htm"
            >  wwhdlg.show_modal 
            >  wwhdlg.navigation_buttons_enabled=true
            

            john

            This is a nice way of testing what sounds work in UI::WebDialog

            [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

            1 條回覆 最後回覆 回覆 引用 0
            • TIGT 離線
              TIG Moderator
              最後由 編輯

              Perhaps...
              var snd=document.createElement('audio'); snd.setAttribute('src', 'zap1.wav'); snd.play();

              TIG

              1 條回覆 最後回覆 回覆 引用 0
              • renderizaR 離線
                renderiza
                最後由 編輯

                your code works fine when using the .html extension with

                <script>
                var snd=document.createElement('audio');
                snd.setAttribute('src', 'zap1.wav');
                snd.play();
                </script>

                But... when using .js extension and trying to open it with "Microsoft (R) Windows Based Script Host" using this code it does't work.

                var snd=document.createElement('audio');
                snd.setAttribute('src', 'zap1.wav');
                snd.play();

                [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                1 條回覆 最後回覆 回覆 引用 0
                • Dan RathbunD 離線
                  Dan Rathbun
                  最後由 編輯

                  of course not... %(#8000BF)[document] is the HTML DOM object, only valid in browsers.

                  I'm not here much anymore.

                  1 條回覆 最後回覆 回覆 引用 0
                  • Dan RathbunD 離線
                    Dan Rathbun
                    最後由 編輯

                    In a UI::WebDialog for old pre-HTML5 which is what PC SketchUp currently uses...

                    try using an %(#8000BF)[<embed>] tag.

                    <EMBED type="audio/x-midi" src="BackInTheSaddle.mid" hidden="true">
                    

                    see [MSDN: <embed>](http://msdn.microsoft.com/en-us/library/ms535245(v)

                    And for the various MIME type strings:

                    Link Preview Image
                    Media type - Wikipedia

                    favicon

                    (en.wikipedia.org)

                    💭

                    I'm not here much anymore.

                    1 條回覆 最後回覆 回覆 引用 0
                    • Dan RathbunD 離線
                      Dan Rathbun
                      最後由 編輯

                      On Windows there is also a lightweight player in the same folder as the normal Media Player.

                      It is named "mplayer2.exe"

                      Command Line options

                      Also the switch -min or /min seems to work to minimize the interface.

                      The path on XP:
                      %(#804000)[%ProgramFiles%/Windows Media Player/mplayer2]

                      in Ruby that would be:
                      player_path = File.join(ENV["ProgramFiles"],"/Windows Media Player/mplayer2")

                      I thot at one time this also was distro'd as an ActiveX control (.ocx file) that could be embedded in webpages ?? (But that may only be MSIE.)

                      I'm not here much anymore.

                      1 條回覆 最後回覆 回覆 引用 0
                      • renderizaR 離線
                        renderiza
                        最後由 編輯

                        @dan rathbun said:

                        In a UI::WebDialog for old pre-HTML5 which is what PC SketchUp currently uses...

                        try using an %(#8000BF)[<embed>] tag.

                        Here is how I implemented the <embed> tag;

                        
                        <script>
                        
                         function playSound(soundfile) {
                         document.getElementById("dummy").innerHTML=
                         "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
                         }
                         
                         playSound('zap1.wav') // I then place this to play the sounds
                         
                        </script>
                        
                        <body>
                        <span id="dummy"></span> //This needs to be in there or it won't work
                        </body>
                        

                        The results:

                        This script plays the sound but causes lag in the game and makes it unplayable. The frame rate pauses until the sound is played and then it continues.

                        This problem didn't happen when using the UI.play_sound or UI.openURL because I asume the UI::WebDialog didn't play any part in handling the sound so it never lagged.

                        I think the best option would have been UI.play_sound if it never clipped the sound when trying to play more than one sound at a time.

                        The UI.openURL is the next best thing because it overlays sound perfectly and it doesn't cause lag but the UI::WebDialog loses focus and I can't play the game no more. I even try to put this <BODY ONBLUR="window.focus()"> on the webdialog but it didn't work.

                        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                        1 條回覆 最後回覆 回覆 引用 0
                        • renderizaR 離線
                          renderiza
                          最後由 編輯

                          @unknownuser said:

                          Actually, the <embed> method is working great for making a sound if you get hit by a ball or if you grab a live or bonus because I don’t mind the pause to the game in that instance…I actually like it!

                          The only problem left to resolve is how to produce a sound every time a ball falls without clipping the sound and lag.

                          Well it doesn't work any good now because I added more bonus and lives items and its just a mess when you grab more than one of does.

                          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                          1 條回覆 最後回覆 回覆 引用 0
                          • renderizaR 離線
                            renderiza
                            最後由 編輯

                            The following solution to be able to play more than one sound simultaneously without sound clipping came to me very randomly. I hope this helps someone and if I ever figure out how to play sounds without small frame freeze then I will post it here. I have gotten less frame freeze using "swf" files but stiil looking to have none slow downs.

                            
                            <html>
                            
                             <head>
                             </head>
                            
                            <body>
                             <span id="dummy"></span> 
                             <span id="dummy2"></span> 
                             <span id="dummy3"></span> 
                            </body>
                            
                            <script>
                            // Sound Effects
                            
                             function playSound(soundfile) {
                             document.getElementById("dummy").innerHTML=
                             "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" mastersound />";
                             }
                             
                             function playSound2(soundfile2) {
                             document.getElementById("dummy2").innerHTML=
                             "<embed src=\""+soundfile2+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" mastersound />";
                             }
                            
                             function playSound3(soundfile3) {
                             document.getElementById("dummy3").innerHTML=
                             "<embed src=\""+soundfile3+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" mastersound />";
                             }
                            
                            // Place Sound effects
                            
                            playSound('sound_1.swf')
                            
                            playSound2('sound_2.swf') 
                            
                            playSound3('sound_3.swf')
                            
                            // ect
                            
                            </script>
                            

                            [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                            1 條回覆 最後回覆 回覆 引用 0
                            • renderizaR 離線
                              renderiza
                              最後由 編輯

                              ...

                              [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                              1 條回覆 最後回覆 回覆 引用 0
                              • renderizaR 離線
                                renderiza
                                最後由 編輯

                                Hi,

                                Its been long time since I talked about this but I want to share some new information regarding sound.

                                My initial goal was to trigger same sound simultaneously and have the ability to overlap sounds without any cutoffs or lag.

                                Just recently I learned how to make use of HTML5 by adding a the following line on web-dialog <meta http-equiv="X-UA-Compatible" content="IE=10"> and this has opened a lot of possibilities with sound.

                                Here is a technique that will enable multiple sounds...

                                On HTML
                                <audio src="sound.mp3" id="snd_test1" preload>

                                On Javascript

                                document.getElementById("snd_test1").cloneNode(true).play()

                                Note: The above line of code is used every time you want to trigger sound. Also for me the only type of sound extension that is working is mp3...I have tested .swf and .wav so far.

                                If anyone has any new info about sound and SketchUp please post it here...Cheers!

                                [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                                1 條回覆 最後回覆 回覆 引用 0
                                • 1
                                • 2
                                • 2 / 2
                                • 第一個貼文
                                  最後的貼文
                                Buy SketchPlus
                                Buy SUbD
                                Buy WrapR
                                Buy eBook
                                Buy Modelur
                                Buy Vertex Tools
                                Buy SketchCuisine
                                Buy FormFonts

                                Advertisement