javascript.song

This is a discussion on javascript.song within the Tech Board forums, part of the Community Boards category; What i want is a button that when pressed starts playing a song then when another button is pressed another ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    15

    javascript.song

    What i want is a button that when pressed starts playing a song
    then when another button is pressed another song starts playing.
    I have been trying to achieve this for a while but nothing seems to be working. Please help

  2. #2
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    Were not just going to write it for you, show us what you have and we'll try to work through it with you.
    PHP and XML
    Let's talk about SAX

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Use Flash. I tend to have allergic reactions to HTML/JavaScript that plays any kind of sound.

    Seriously though, there just isn't a portable way to do it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    >>Use Flash

    please...no. Sorry Bee but most people are still on dialup, flash is a bad idea. For that matter playing a song is a bad idea anyway, but since there's buttons involved I'm guessing there's a purpose other than to tick off visitors.

    >>Seriously though, there just isn't a portable way to do it.

    last i checked html/javascript rendered in every major browser on every major OS...flash requires a plugin...
    PHP and XML
    Let's talk about SAX

  5. #5
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Actually, I'm going to disagree with you Waldo... if you're going to annoy your users with sound, you might as well go full monty and do it right. Flash is much better for handling sound files and I'd rather see someone use Flash to play sound over a javascript method (keep in mind that probably just as many people turn off javascript as those that don't have the Flash plugin).

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Quote Originally Posted by Waldo2k2
    >>Use Flash

    please...no. Sorry Bee but most people are still on dialup, flash is a bad idea.
    Let me get that straight. You're worried that I suggest using a solution that requires high bandwidth for a problem that requires high bandwidth anyway, because people with low bandwidth would have problems accessing it?
    Yeah, right ...

    For that matter playing a song is a bad idea anyway, but since there's buttons involved I'm guessing there's a purpose other than to tick off visitors.
    Indeed there is. I've no doubt that the OP has the most honourable of intentions. But I do not think that HTML/JS is a good solution for it. In my opinion, this multimedia stuff belongs to Flash or similar technologies. (I believe IE can do SMIL.)

    >>Seriously though, there just isn't a portable way to do it.

    last i checked html/javascript rendered in every major browser on every major OS...flash requires a plugin...
    Last I checked there was no <sound> tag in HTML and no window.playSound in JavaScript. The <bgsound> tag which is supported by some browsers is annoying and not suited for this purpose. Every way of playing sounds with JavaScript involves creating an instance of some plugin, usually Windows Media Player, so it requires a plugin anyway. As for compatibility, Flash is available for Linux and Windows on all x86-32 chips, and on Macs of various kinds. In addition, a limited form (no scripting) of Flash is available for just about every architecture on Unix systems in the form of the LGPL'ed swfdec library. If that wasn't enough, there are two projects aiming to write a complete and full-featured open-source Flash player: gplflash, which currently is bound to X-based systems, and my own OpenFlash, which is not in any state of completion but is developed to be cross-platform and cross-architecture.
    The Flash plugin can be used by every major browser: IE, Gecko-based, Opera and KHTML-based.
    Windows Media Player is available for ... Windows. Mac too? Not sure. This plugin is as far as I know not available for KHTML-based browsers like Safari. Not sure about Opera. The method of addressing it is different between Mozilla and IE. In other words, using it is a nightmare.

    I stand by my point. Use Flash.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    >>Let me get that straight. You're worried that I suggest using a solution that requires high bandwidth for a problem that requires high bandwidth anyway, because people with low bandwidth would have problems accessing it?<<

    yeah that probably made more sense in my head, but that happens. I was thinking more along the lines of the bloat that flash can add to a page, that's why I also went on to say that sounds in a web page are a bad idea anyway.

    >>this multimedia stuff belongs to Flash or similar technologies<<

    which is true, that's why they're deemed as such...however I think that there are low impact ways to do it in js/html. I know there's no sound tag (thank god), but wouldn't it be possible to just use an embed statement for a .mp3/.ogg/.etc file in which case the browser would launch the correct application according to what's associated with it's type? That would allow the user to write an embed tag with a write() command called when clicking on the button...as far as stopping it goes I'm not really sure. But since he asked about html/javascript I was trying to think of a good way to do it with that method...it doesn't help the fact that personally I hate flash....

    Anyway, let's just wait until smonk writes back....I kinda have doubts that he has actually tried to do this on his own.
    PHP and XML
    Let's talk about SAX

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Actually, write() can't be called after the page has finished loading, and never in XHTML. It would have to be some DOM manipulation. Yes, it would probably be possible. It would not be elegant.

    But I agree that sound in a web page is bad. However, this here sounds as if the author wants to do something like make a page for some band, with small sound samples of their works that you can play.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    sounds good enough to me, and elegant is really a relative term sometimes (maybe not in this case) but there's got to be some pretty dirty code underlying some flash files. Most of it is done with a GUI after all (unless this guy happens to be a god with actionscript). But I figure we just wait until the thread starter gets back...if he comes back.
    PHP and XML
    Let's talk about SAX

  10. #10

  11. #11
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    I am not going to use sound as a way to annoy my visitors.

  12. #12
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    By the way i tried to do something like this
    Code:
    <html>
    <head>
    <script language="javascript" Type="text/javascript">
    function PlaySong(songNo)
    {
    if(songNo == 1)
    	{
    	<bgsound src="son1.wma" loop="infinite">
    	}
    if(songNo == 2)
    	{
    	<bgsound src="son2.wma" loop="infinite">
    	}
    }
    
    </script>
    
    </head>
    <input type="button" value="song1.wma" onclick=PlaySong(1)>
    <input type="button" value="song2.wma" onclick=PlaySong(2)>
    </body>
    </htm>
    Please Help It generates an error message

  13. #13
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    That would be because you can't just output HTML from JavaScript that way. There's document.write, but it won't work once the page has loaded.

    You can either use innerHTML or the DOM to modify the document. But as I said before, I don't think <bgsound> is a good choice. Perhaps an <object>.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21