Results 1 to 6 of 6
  1. #1
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Embedding sounds in a web page

    (This is a duplicate post that I answered in two parts...try not to get too confused! The original thread started here.)
    <hr>Hey Mark!!!

    The other item I have really wanted to accomplish is getting the "music" to play in Moz without having to actually click on the link. I know (or I think?) that it can be done, but my coding just isn't doing it! If you have any suggestions for that - I am all "ears"!! <img src=/S/grin.gif border=0 alt=grin width=15 height=15> <hr>
    There is no standard way of doing this in all browsers. Before you go any further, also consider whether you really want to do this. Background sounds have a way of annoying people. An example: someone is surfing the net, when suddenly their computer starts playing music for everyone in the office to hear, revealing that the happy surfer isn't really working.

    OK, so I've warned you - this is not to say that background sounds are a bad idea all of the time, but a lot of people do not like them. If you do not plan to provide a means of controlling whether the sound is playing or not, the annoyance is greater still...but here is something that will help.

    To prevent error messages and make sure that it plays, you can use a little script that sniffs out the browser and inserts the proper HTML into the page as it is rendered. Thus:
    <pre>< ! - -
    var filename="some_music.mid";
    if (navigator.appName == "Microsoft Internet Explorer")
    document.writeln ('<BGSOUND SRC="' + filename + '">');
    else if (navigator.appName == "Netscape")
    document.writeln ('<EMBED SRC="' + filename + '" AUTOSTART=TRUE>');
    // - - >

    <noscript>
    <BGSOUND SRC="some_music.mid">
    </noscript>
    </pre>

    Please note that I had to chop up the HTML comment tags so that the Lounge would display this correctly.)

    Here is what the code means:
    1. <LI>If the browser is Internet Explorer, write the BGSOUND tag
      <LI>Else, if the browser identifies itself as Netscape, write out an EMBED tag.
      <LI>The NOSCRIPT section is intended for browsers that do not understand script languages (admittedly few).
    Sorry it's not any cleaner than that; since there is no standard a kludge is all you are left with if you really want to embed sounds in a page.
    -Mark

  2. #2
    Bronze Lounger
    Join Date
    Feb 2001
    Posts
    1,424
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Embedding sounds in a web page

    Hi Mark,

    I use FP2003 (a recent purchase actually) and I have been trying to use the script that you have posted. Since I am not quite getting the results that I want, I may need a bit of <img src=/S/bash.gif border=0 alt=bash width=35 height=39> <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

    So I copied the script and pasted it between the <head> </head> tags. Upon checking the "preview", I see part of the script! So I must be missing a step someplace along the line. Or should I not be putting the whole script on? The following text is the part that is appearing on the preview page:
    < ! - - var filename="some_music.mid"; if (navigator.appName == "Microsoft Internet Explorer") document.writeln (''); else if (navigator.appName == "Netscape") document.writeln (''); // - - >

    I haven't gotten as far as checking whether I can get music to play yet! Since I only know basic HTML or using an application like FP, you can see that I am clueless when it comes to adding scripts. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> TIA for your patience!

    PS: I do realize that I need to insert the proper link to the music that I want to play when my page opens! <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> But as mentioned above, I haven't gotten that far to try it out.


    "Peace begins with a smile. "-- Mother Teresa

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Embedding sounds in a web page

    Did you remove the spaces in the HTML comments from my original post? I've attached the script as a text file to this post as it should really be, try copying it directly from the attachment and inserting it into the HTML code directly.

    Also, some scripts will not execute properly in the preview section of FrontPage. You may have to publish the page to make it work properly, or at the very least preview it in an external browser window. I have found that FP's preview is a poor excuse for anything and rarely gives reliable output, even though it uses Internet Explorer's rendering engine, it does not seem to approximate the browser itself very well.
    Attached Files Attached Files
    -Mark

  4. #4
    Bronze Lounger
    Join Date
    Feb 2001
    Posts
    1,424
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Embedding sounds in a web page

    Hi Mark,

    Yep, that is what the problem was - a couple of extra spaces that I sure didn't notice! I am not used to working with this type of script - only straight and simple HTML and using FP.

    So I am still trying......................I have the test page published here. When I open it in Firefox, it still doesn't want to play my midi. If I use "launchy" to open IE, the song starts right up! I inserted the script you provided <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> and tried it with just the script first. It didn't work for me so I went back in and also put the midi into the page through FP.

    I haven't a clue what to do with this next or what I might have done incorrectly. I realize that constant music playing will drive some people nuts, but not too many stay on that first page for very long anyway!! And I am determined to 'get this right'!

    TIA for any additional help that you or anyone can provide!

    It is kind of scary, letting the whole world know of my inabilities! Oh well........... <img src=/S/grin.gif border=0 alt=grin width=15 height=15>


    "Peace begins with a smile. "-- Mother Teresa

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Embedding sounds in a web page

    Try putting the script into the BODY section of the page, rather than in the HEAD section. I'm not sure it will help, but it seems logical to me. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  6. #6
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Embedding sounds in a web page

    Here's the problem - and it's not entirely your fault; I should have told you to add this in your page code.

    To make the script work, you need to add the following tags:<pre>< script language="Javascript >
    ....script script script....
    < /script ></pre>

    Again, remove the extraneous spaces (this time around the SCRIPT tags). I had to put them in so the Lounge would not choke on the tags. If you add those small elements, it should work like a charm.

    Jefferson suggested putting this into the body of the document. So far as I know, it won't make any real difference - it doesn't when I test. The advantage to putting it in the body is that you can choose where the plug-in will appear.
    -Mark

Posting Permissions

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