Music in background w/ onload, function, or any other method.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Death Slaught
    Top Contributor
    • Aug 2007
    • 1137

    Music in background w/ onload, function, or any other method.

    I need a function that plays a song in the background ( in other words the user can't stop/start the music they have to go to another page or listen to it )

    I'm not the greatest at JavaScript I don't do much with it, but I'm hoping to change that.

    It doesn't really make a difference if you can do it wile the page is loading or it starts when the page is completely loaded.

    Thanks, Death
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    That would be annoying, but here's a link.

    Comment

    • Death Slaught
      Top Contributor
      • Aug 2007
      • 1137

      #3
      Originally posted by acoder
      That would be annoying, but here's a link.
      The type of site I'm making, the users will expect music, so it wont be "annoying", and I've been to w3schools, already thats why I'm asking for a way to put it into a function.

      Thanks anyway, Death

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by Death Slaught
        The type of site I'm making, the users will expect music, so it wont be "annoying"
        Maybe that should've been "could be".

        I don't play much with sound, but you could try using an iframe linked to a sound file. Do you mind the sound player showing on the screen?

        Comment

        • Death Slaught
          Top Contributor
          • Aug 2007
          • 1137

          #5
          Originally posted by acoder
          Maybe that should've been "could be".

          I don't play much with sound, but you could try using an iframe linked to a sound file. Do you mind the sound player showing on the screen?
          Yea I wan't it to be in the background.

          Thanks, Death

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by Death Slaught
            Yea I wan't it to be in the background.

            Thanks, Death
            Have a play with this. Instead of playing using a button, you could add it onload.

            Comment

            • Death Slaught
              Top Contributor
              • Aug 2007
              • 1137

              #7
              Originally posted by acoder
              Have a play with this. Instead of playing using a button, you could add it onload.
              Thanks, but it's still not what I'm looking for, I wan't the music to play in the background yes, but I wan't it in a JavaScript function, onload would be fine as long as it's something like this. (no this doesn't work it's just something i've tried).



              Code:
              function play()
              
              {
              window.bgsound="location";
              }

              [HTML]<body onload="play()" >
              </body>[/HTML]

              Thanks again, Death

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by Death Slaught
                Thanks, but it's still not what I'm looking for, I wan't the music to play in the background yes, but I wan't it in a JavaScript function, onload would be fine as long as it's something like this. (no this doesn't work it's just something i've tried).
                Have you tried something like this:
                [CODE=javascript]function play() {
                embed = document.create Element("embed" );
                embed.setAttrib ute("src", "soundfile.wav" );
                embed.setAttrib ute("hidden", true);
                embed.setAttrib ute("autostart" , true);
                document.body.a ppendChild(embe d);
                }[/CODE]and call it onload.

                Comment

                • helimeef
                  New Member
                  • Sep 2007
                  • 77

                  #9
                  Jeez okay, the last reply was probably the best recommendation. But just a few issues with making music play in the background:
                  1. It must not be copyrighted, or you must be the owner.
                  2. You better put play/pause and next/previous button, or else your users will get annoyed with the music constantly playing and restarting every time they refresh.
                  3. Although your users will expect to hear music, your looking at a rare audience. What about visitors? Stumblers? They have no idea your site will play music, unless you put "THIS SITE PLAYS MUSIC" in your title tag :)
                  Good luck.

                  Comment

                  • Death Slaught
                    Top Contributor
                    • Aug 2007
                    • 1137

                    #10
                    Originally posted by acoder
                    Have you tried something like this:
                    [CODE=javascript]function play() {
                    embed = document.create Element("embed" );
                    embed.setAttrib ute("src", "soundfile.wav" );
                    embed.setAttrib ute("hidden", true);
                    embed.setAttrib ute("autostart" , true);
                    document.body.a ppendChild(embe d);
                    }[/CODE]and call it onload.
                    Thanks just what I needed.

                    - Death

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      Originally posted by helimeef
                      Jeez okay, the last reply was probably the best recommendation. But just a few issues with making music play in the background:
                      1. It must not be copyrighted, or you must be the owner.
                      2. You better put play/pause and next/previous button, or else your users will get annoyed with the music constantly playing and restarting every time they refresh.
                      3. Although your users will expect to hear music, your looking at a rare audience. What about visitors? Stumblers? They have no idea your site will play music, unless you put "THIS SITE PLAYS MUSIC" in your title tag :)
                      Good luck.
                      Good points. I'd say a pause/stop button wouldn't do any harm.

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Originally posted by Death Slaught
                        Thanks just what I needed.

                        - Death
                        Glad to hear you got it working. Remember to take care with sound.

                        Comment

                        Working...