why is "how to play a sound with Javascript" such a rare topic?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jake Barnes

    why is "how to play a sound with Javascript" such a rare topic?


    I did a search on the newsgroup comp.lang.javas cript. I was searching
    for "how to play a sound with Javascript". I'm somewhat suprised that
    the majority of entries are from the 1990s, and there are almost no
    posts from the last 3 years:



    Even after sorting by date, there don't appear any entries more recent
    than 2006, and there are only 3 from 2006.

    If I were to chart the frequency of questions about sound on a graph,
    it would appear there was great interest in the question during the
    1990s, and then that interest faded away, disappearing almost entirely
    after 2004.

    Why is that? Did Flash become good enough and widespread enough that
    programmers now rely on it completely when trying to get sound to play
    on a site? Is there the sense that it is too difficult to use
    Javascript to play a sound on a web page?

    I was working on some Ajax chat software and I was asked to make a
    sound play when someone posted a new message to a chat room. I was
    thinking of doing this in a pure-Javascript way, but perhaps that is
    to be advised against? Should I use Flash instead?

    I asked my friends for a pure Javascript solution and they pointed me
    to a script that still involves Flash:

    The Truth About Loans With No Credit CheckUnfortunately, no matter what you might have seen during your last Google search, we're here to tell you the truth about loans without a credit check. Simply put - they don't exist, at least not from lenders that you can trust. That's because the Financi



  • David Mark

    #2
    Re: why is "how to play a sound with Javascript&quot ; such a rare topic?

    On Feb 26, 12:30 am, Jake Barnes <lkrub...@geoci ties.comwrote:
    I did a search on the newsgroup comp.lang.javas cript. I was searching
    for "how to play a sound with Javascript". I'm somewhat suprised that
    the majority of entries are from the 1990s, and there are almost no
    posts from the last 3 years:
    >
    http://groups.google.com/group/comp....rch?group=comp...
    >
    Even after sorting by date, there don't appear any entries more recent
    than 2006, and there are only 3 from 2006.
    It is a rare Web page that needs to make use of sounds.
    >
    If I were to chart the frequency of questions about sound on a graph,
    it would appear there was great interest in the question during the
    1990s, and then that interest faded away, disappearing almost entirely
    after 2004.
    >
    Why is that? Did Flash become good enough and widespread enough that
    programmers now rely on it completely when trying to get sound to play
    on a site? Is there the sense that it is too difficult to use
    Javascript to play a sound on a web page?
    Flash is not "good enough" for much of anything IMO. It is a rare Web
    page that needs to make use of Flash.

    There may be a sense that it is too difficult to play sounds with
    JavaScript, but it is nonsense. The issues involved are virtually
    identical to those involved with using Flash. The difference is that
    there are tons of (incompetent) Flash scripts out there (most notably
    the one provided by Adobe), but few that deal with audio plug-ins.
    >
    I was working on some Ajax chat software and I was asked to make a
    sound play when someone posted a new message to a chat room. I was
    thinking of doing this in a pure-Javascript way, but perhaps that is
    to be advised against? Should I use Flash instead?
    No, you had it right to begin with.
    >
    I asked my friends for a pure Javascript solution and they pointed me
    to a script that still involves Flash:
    >
    http://www.boutell.com/newfaq/creating/scriptsound.html
    Then they pointed you to an inappropriate script.

    If you are writing an Ajax chat application, then you should be able
    to tackle this. As with Flash, you need two branches, one that checks
    the plugins and/or mimeTypes collections to determine support for your
    chosen format and a fallback for IE and its various derivations (e.g.
    old AOL browsers, which have no such collections (the feature
    detection pattern should be obvious.)

    The first branch adds an object element to the body to play a sound
    and removes it after a suitable delay (which cannot be calculated
    exactly as it takes time to download the file and load the plug-in.)
    I use two object elements to allow for music and sounds to play
    simultaneously. You can "preload" the plug-in with dummy (silent)
    audio file(s) when the page loads, but still need to pad the duration
    to allow time for the initial download.

    The second branch adds a bgsound element (or two) to the head and
    changes the src property to play sounds. You can actually preload the
    sound files with this method as you can play sounds silently by
    manipulating the volume property. This works much better than the
    other method as you never have to remove the elements, so there is no
    need to pad the play time.

    Comment

    • SAM

      #3
      Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

      Jake Barnes a écrit :
      >
      I asked my friends for a pure Javascript solution and they pointed me
      to a script that still involves Flash:
      >
      http://www.boutell.com/newfaq/creating/scriptsound.html
      It's the best.

      Anyway it is impossible to play a sound in JS ...
      a sound can only be played by a plug-in and there was so much plug-ins
      to play sound whom each one with its proper JS commands, in these
      conditions how to be sure to have thought to all of them?

      Today it is not very important any more to use a heavy mp3 instead of
      light midi
      Flash play mp3 and can be driven via JS
      Flash is present on 90% of home computers
      so ... at this date ... it's the solution

      --
      sm

      Comment

      • David Mark

        #4
        Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

        On Feb 26, 9:21 am, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
        wrote:
        Jake Barnes a écrit :
        >
        I asked my friends for a pure Javascript solution and they pointed me
        to a script that still involves Flash:
        >>
        It's the best.
        How so?
        >
        Anyway it is impossible to play a sound in JS ...
        a sound can only be played by a plug-in and there was so much plug-ins
        to play sound whom each one with its proper JS commands, in these
        conditions how to be sure to have thought to all of them?
        You really don't have to consider the plug-in at all.
        >
        Today it is not very important any more to use a heavy mp3 instead of
        light midi
        Flash play mp3 and can be driven via JS
        I didn't follow that, but you can certainly play MP3's using the
        methods I described. In fact, they work best for longer clips as most
        plug-ins will stream them.
        Flash is present on 90% of home computers
        That isn't a comforting statistic. And not all of those Flash
        installations will support interaction with JavaScript.
        so ... at this date ... it's the solution
        Of course, there aren't any decent scripts out there for Flash.

        Quoting the first two lines from the "SoundManag er" script:

        var isIE = navigator.appNa me.toLowerCase( ).indexOf('inte rnet explorer')
        +1;
        var isMac = navigator.appVe rsion.toLowerCa se().indexOf('m ac')+1;

        I stopped reading after that.

        And it appears you have to convert every sound effect to MP3. On the
        plus side, it is very responsive, but do you really need UI sounds in
        a Web page? The OP just wants to sound a chime periodically.

        Comment

        • Kevin Scholl

          #5
          Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

          On Feb 26, 10:53 am, David Mark <dmark.cins...@ gmail.comwrote:
          Flash is present on 90% of home computers
          >
          That isn't a comforting statistic. And not all of those Flash
          installations will support interaction with JavaScript.
          Nor does the presence of Flash necessarily mean that it's turned on. A
          number of my colleagues (myself included) utilize a plugin that blocks
          Flash from loading automatically (replacing it with the Flash icon so
          we know it's there) unless we specifically click it to activate.

          Comment

          • SAM

            #6
            Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

            David Mark a écrit :
            On Feb 26, 9:21 am, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
            wrote:
            >Jake Barnes a écrit :
            >>
            >>I asked my friends for a pure Javascript solution and they pointed me
            >>to a script that still involves Flash:
            >>http://www.boutell.com/newfaq/creating/scriptsound.html
            >It's the best.
            Oooops!
            I thought we told of this one :
            <http://www.schillmania .com/projects/soundmanager2/>
            issued from :
            <http://www.schillmania .com/projects/soundmanager/>
            (perhaps are they all the same ?)

            (snip)
            Quoting the first two lines from the "SoundManag er" script:
            I've seen that too :-/
            var isIE = navigator.appNa me.toLowerCase( ).indexOf('inte rnet explorer')
            +1;
            var isMac = navigator.appVe rsion.toLowerCa se().indexOf('m ac')+1;
            >
            I stopped reading after that.
            I only have a look to the code after having pushed some of proposed
            buttons in soundManager_1 that did noises (yes they did !)
            And it appears you have to convert every sound effect to MP3.
            And then ?
            The sound has to be coded anyway (even it is a midi), no ?
            On the
            plus side, it is very responsive, but do you really need UI sounds in
            a Web page? The OP just wants to sound a chime periodically.
            I don't say the OP has to have its page to download an elephant if he
            just needs a mouse.
            I say only that soundmanager is the best (the easiest way) to serve sounds.
            There are some others Flash mp3 players on the Net but most of them are
            not so efficient (even if they probably be used too).
            (I like this one : http://www.alsacreations.fr/dewplayer )

            But I'am seriously very curious to see *with an example* how you do to
            play a sound on demand (a "clic" when clicking a link for instance)
            without using Flash and without downloading the sound each time.
            Because personally I can't do it.

            --
            sm

            Comment

            • SAM

              #7
              Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

              Kevin Scholl a écrit :
              On Feb 26, 10:53 am, David Mark <dmark.cins...@ gmail.comwrote:
              >
              >>Flash is present on 90% of home computers
              >That isn't a comforting statistic. And not all of those Flash
              >installation s will support interaction with JavaScript.
              >
              Nor does the presence of Flash necessarily mean that it's turned on. A
              number of my colleagues (myself included) utilize a plugin that blocks
              Flash from loading automatically (replacing it with the Flash icon so
              we know it's there) unless we specifically click it to activate.
              You're right.
              I've recently downloaded a flash blocker.
              And the JS also can be disabled too.

              The Net will kill the Net ... :-(

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

                David Mark wrote:
                If you are writing an Ajax chat application, then you should be able
                to tackle this. As with Flash, you need two branches, one that checks
                the plugins and/or mimeTypes collections to determine support for your
                chosen format and a fallback for IE and its various derivations (e.g.
                old AOL browsers, which have no such collections (the feature
                detection pattern should be obvious.)
                >
                The first branch adds an object element to the body to play a sound
                and removes it after a suitable delay (which cannot be calculated
                exactly as it takes time to download the file and load the plug-in.)
                I don't see a need for removing the element, especially not because of
                the uncertainty you mentioned.

                Audio compression aside, I also don't see a need for Flash here. User
                agents are capable to load the audio resource directly with the object
                element. You will have to use another branch for MSHTML, though, that
                uses a CLSID to trigger the Windows Media Player ActiveX control.
                The second branch adds a bgsound element (or two) to the head and
                changes the src property to play sounds.
                There really is no need for that, unless you want to support IE 4.


                PointedEars
                --
                var bugRiddenCrashP ronePieceOfJunk = (
                navigator.userA gent.indexOf('M SIE 5') != -1
                && navigator.userA gent.indexOf('M ac') != -1
                ) // Plone, register_functi on.js:16

                Comment

                • Joost Diepenmaat

                  #9
                  Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

                  Thomas 'PointedEars' Lahn <PointedEars@we b.dewrites:
                  Audio compression aside, I also don't see a need for Flash here. User
                  agents are capable to load the audio resource directly with the object
                  element.
                  This is an unusually sweeping statement coming from you. My main browser
                  (firefox 2.something on debian) certainly doesn't play mp3s when they're
                  provided via an object tag.

                  --
                  Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

                  Comment

                  • David Mark

                    #10
                    Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

                    On Feb 26, 6:17 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                    wrote:
                    David Mark wrote:
                    If you are writing an Ajax chat application, then you should be able
                    to tackle this.  As with Flash, you need two branches, one that checks
                    the plugins and/or mimeTypes collections to determine support for your
                    chosen format and a fallback for IE and its various derivations (e.g.
                    old AOL browsers, which have no such collections (the feature
                    detection pattern should be obvious.)
                    >
                    The first branch adds an object element to the body to play a sound
                    and removes it after a suitable delay (which cannot be calculated
                    exactly as it takes time to download the file and load the plug-in.)
                    >
                    I don't see a need for removing the element, especially not because of
                    the uncertainty you mentioned.
                    You have to remove it, set the src property and re-add it to get a new
                    sound to play (at least in the browsers I have tested.) And then
                    there is the issue of fast history navigation. Leave the object in
                    place and the last sound played will play again when you return to the
                    page, which is very annoying.
                    >
                    Audio compression aside, I also don't see a need for Flash here.  User
                    agents are capable to load the audio resource directly with the object
                    element.  You will have to use another branch for MSHTML, though, that
                    uses a CLSID to trigger the Windows Media Player ActiveX control.
                    >
                    The second branch adds a bgsound element (or two) to the head and
                    changes the src property to play sounds.
                    >
                    There really is no need for that, unless you want to support IE 4.
                    It works far better in IE than the object approach. It is faster and
                    does not require ActiveX.

                    Comment

                    • SAM

                      #11
                      Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

                      Thomas 'PointedEars' Lahn a écrit :
                      >
                      I don't see a need for removing the element, especially not because of
                      the uncertainty you mentioned.
                      OK
                      Audio compression aside, I also don't see a need for Flash here. User
                      agents are capable to load the audio resource directly with the object
                      element.
                      To load, probably, but to play it ? ... less sure.
                      You will have to use another branch for MSHTML, though, that
                      uses a CLSID to trigger the Windows Media Player ActiveX control.
                      What I would like to know is how you reactivate (replay) the sound
                      embeded in the object ? (without reloading the sound's file)
                      with any browser.

                      (and how an object can play a sound : certain of my browsers need the
                      tag embed)
                      >The second branch adds a bgsound element (or two) to the head and
                      >changes the src property to play sounds.
                      >
                      There really is no need for that, unless you want to support IE 4.
                      And my NC4 ? do you think to my NC4 ? (with its AudioLive)

                      --
                      sm

                      Comment

                      • David Mark

                        #12
                        Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

                        On Feb 26, 6:24 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
                        Thomas 'PointedEars' Lahn <PointedE...@we b.dewrites:
                        >
                        Audio compression aside, I also don't see a need for Flash here.  User
                        agents are capable to load the audio resource directly with the object
                        element.
                        >
                        This is an unusually sweeping statement coming from you. My main browser
                        (firefox 2.something on debian) certainly doesn't play mp3s when they're
                        provided via an object tag.
                        >
                        Either you do not have an appropriate plug-in installed (something
                        that any such script would need to detect), plug-ins are disabled or
                        the object markup is wrong.

                        Comment

                        • David Mark

                          #13
                          Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

                          On Feb 26, 6:41 pm, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
                          wrote:
                          Thomas 'PointedEars' Lahn a écrit :
                          >
                          >
                          >
                          I don't see a need for removing the element, especially not because of
                          the uncertainty you mentioned.
                          >
                          OK
                          No, Thomas is incorrect here. See my follow-up.
                          >
                          Audio compression aside, I also don't see a need for Flash here.  User
                          agents are capable to load the audio resource directly with the object
                          element.
                          >
                          To load, probably, but to play it ? ... less sure.
                          It works. At least in the browsers and plug-ins I have tested.
                          >
                          You will have to use another branch for MSHTML, though, that
                          uses a CLSID to trigger the Windows Media Player ActiveX control.
                          >
                          What I would like to know is how you reactivate (replay) the sound
                          embeded in the object ? (without reloading the sound's file)
                          with any browser.
                          I explained that.
                          >
                          (and how an object can play a sound : certain of my browsers need the
                          tag embed)
                          Perhaps NN4. That's about it. If you are going to *nest* objects
                          with param elements, then you need the non-standard embed element to
                          support older versions of Safari. Most Flash scripts wrap an object
                          around an embed, whether they need to or not. Regardless, the process
                          I described does not nest objects.
                          >
                          The second branch adds a bgsound element (or two) to the head and
                          changes the src property to play sounds.
                          >
                          There really is no need for that, unless you want to support IE 4.
                          >
                          And my NC4 ? do you think to my NC4 ? (with its AudioLive)
                          NN4? Perhaps you can tell me (see my other post.) I haven't tested
                          it in almost a decade (and when I did, it was surely with an embed
                          element.)

                          Comment

                          • Joost Diepenmaat

                            #14
                            Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

                            David Mark <dmark.cinsoft@ gmail.comwrites :
                            Either you do not have an appropriate plug-in installed (something
                            that any such script would need to detect), plug-ins are disabled or
                            the object markup is wrong.
                            Currently I don't have a plugin installed. I used to have a plugin
                            installed (I think it was the VLC plugin), but it always set the volume
                            to 0% and wouldn't auto-start so it was pretty useless.

                            In any case, if you're relying on plugins anyway, my /guess/ would be
                            that flash has the largest install base of any plugin.

                            What I'm getting at is that just using <objecttags is no guarantee
                            whatsoever and that, currently, using flash is probably a very sane
                            fallback/default if you want reasonably reliable scriptable sound.

                            --
                            Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

                            Comment

                            • Thomas 'PointedEars' Lahn

                              #15
                              Re: why is &quot;how to play a sound with Javascript&quot ; such a rare topic?

                              David Mark wrote:
                              On Feb 26, 6:24 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
                              >Thomas 'PointedEars' Lahn <PointedE...@we b.dewrites:
                              >>Audio compression aside, I also don't see a need for Flash here. User
                              >>agents are capable to load the audio resource directly with the object
                              >>element.
                              >This is an unusually sweeping statement coming from you. My main browser
                              >(firefox 2.something on debian) certainly doesn't play mp3s when they're
                              >provided via an object tag.
                              >
                              Either you do not have an appropriate plug-in installed (something
                              that any such script would need to detect), plug-ins are disabled or
                              the object markup is wrong.
                              I don't think that with this approach the script would need to detect
                              whether there was an appropriate plugin installed (is that even possible
                              in !MSHTML?). If there is not, simply nothing happens.


                              PointedEars
                              --
                              realism: HTML 4.01 Strict
                              evangelism: XHTML 1.0 Strict
                              madness: XHTML 1.1 as application/xhtml+xml
                              -- Bjoern Hoehrmann

                              Comment

                              Working...