SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Play a sound on loading

    I want to play sounds on loading. Can you do that without using flash.

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Here is a pretty good article about playing sound:
    http://www.scriptwell.net/howtoplaysound.htm

    Regardless which one you choose to use to play the sound, to get it to work when the page finishes loading, just have the function that starts it called by the body's attribute "onload". So, it'd be something like this:
    Code:
    <body onload="playSound()">

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Bad bad practice if you want your visitors to stay best not to do this.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I hate it when web sites play sound without my consent. It is probably the thing I hate the most of all things on the internet. A lot of people, like me, listen to music while at the computer and having other (inferior) sounds clashing with it is utterly horrible.

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree. Don't force music on your users. Give them an option to play it, but don't start playing it for them or you'll only push them away.

  6. #6
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Now, his site may be one where users expect sound to play when it loads.

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't expect sound to play on ANY site I visit when it loads. I can't think of a use case where it makes sense either.

  8. #8
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with the others that it is very annoying when web pages plays sounds or music when I visit a website.

    But, the question was how to play a sound and there is no real easy way to achieve this today (note that you can though, using flash or other work-arounds).

    The HTML 5 specification provides an API that makes it really easy to play sound on the web. Opera 9 and the upcoming Safari 3.1 has already implemented this.

    The code is quite easy and looks like this
    Code:
    var audio = new Audio("ooops_i_did_it_again.mp3");
    audio.play();

  9. #9
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That's pretty cool and much better than using plugins, which are slow to load, can be difficult to get working and the user may or may not have.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •