JavaScript - Sound Onclick Help...
Hi there
Looking at adding a sound file to a game to play when an image, a .png image is pressed.. it will be a simple 1sec (or less) sound file i.e. bell, whistle etc. Just looking at some help on where to start with the code. Many thanks LL Similar TutorialsI was wondering if there is a javascript code that works in all browsers and will allow when a person clicks on a certain tab I have that it plays a short beep.
Hi I have created a page using tables and found abit of javascript off the net where I could get a little soundbite to play when an image is clicked. It worked fine. However I have now converted the page into CSS and even with using the same code the sound no longer plays. Can anyone share any light on this please?? here is a snippet of my page code that shows the javascript. Code: <title>Joho-Designs-Home</title> <link rel="stylesheet" type="text/css" href="johogallery.css" /> <script language="javascript" type="text/javascript"> function playSound(soundfile) { document.getElementById("dummy").innerHTML= "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />"; } </script> <li><embed name="mySound" src="sounds/SQUEAK3.wav" loop=false autostart=false hidden= true><a href="#" onclick="playSound('sounds/SQUEAK3.wav');"><img src="menu/row3sq3_squeak_OP.png" border="0" alt="1"/></a></li> Thanks and look forward to replies!! I'm currently working on a project and I am doing a bunch of image switching. I'm having a problem with the following... I have seven medium image objects and one small one. One is at the top and the other 7 are below. When one of the 7 is clicked, it then becomes the one up top and the one up top then takes the place of the image clicked. This needs to be able to happen no matter which of the seven i click. Also when you click one of the seven it runs a script to change 9 other images in the center of the page. this isnt too important because i have it working already. What i have is, each of the seven images run their function that changes the 9 center images and then it runs another function. What i need is for that function to determine which company for example(shaws, lowes, target) the top image belongs to and replace the image that was clicked with the top one. But i also need to replace the NAME="" and ONCLICK="function()" with the proper ones for the original company up top. Please if you can understand what im trying to do let me know, if you need further clarification i can do so. i can draw a picture of what im trying to do or the layout if needed but i cant necessarily show anyone the project due to a non-disclosure. Hey guys, I need some help. I have divs placed in a html document, and what I need to do is have a sound play when a person is to hover their mouse over the,. I used this code that I've butchered together from researching on the internet, but it just isn't working. The sound plays automatically as soon as the site loads. Can you please help me? Here is my code: Code: <html> <head> <script> function EvalSound(soundobj) { var thissound= eval("document."+soundobj); thissound.Play(); } </script> <embed src="C.mp3" autostart=false width=0 height=0 name="C" enablejavascript="true"> <embed src="D.mp3" autostart=false width=0 height=0 name="D" enablejavascript="true"> </head> <link rel="stylesheet" type="text/css" href="NavTest.css"> <div id=red alt="#" onMouseOver="EvalSound('C')"></div> <div id=blue alt="#" onMouseOver="EvalSound('D')"></div> </html> Thank you! [: Sorry, maybe I should also mention that my knowledge of Javascript is NONE! :| Hi I'm wanting to add a sound to an image when it is clicked. Basically when you click a picture of a mouse is squeaks. Can someone help me with the code for this? I think its Javascript which is a aboit scary for me ha! I'm hoping its not to complicated and confusing for my brain!! Cheers C Hello Everyone! I am looking for help with this script and I was wondering if someone could help me out? I want to play a sound on a mouse click, which there are a ton of scripts out there that do this. Here is my problem I want to be able to let the users shut the sound on and off. This is for a feature to my site that I am building that is just using javascript and html. Here is what I have so far below. I would also like to have a div to show if the sound is on or off. The only thing that I am looking for the javascript to play and stop the sound file. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script type="text/javascript"> var theSound = "on"; function playSound(){ if(document.getElementById("mute").checked == false){ document.getElementById("theSound").style.display = "block"; //isert play sound code here } } function muteSound(){ document.getElementById("theSound").style.display = "none"; //insert stop sound code here } </script> </head> <body> <form name="soundTest"> <input name="sound" type="checkbox" value="on" id="mute" />Mute </form> <p onmouseover="playSound()" onmouseout="muteSound()">Mouseover this to make the "Sound".</p> <!--This is just a div that represents a sound playing.--> <div id="theSound" style="display:none; background:#FF0000; padding:10px; font-size:36px">SOUND!</div> </body> </html> Note: That this script just shows a mute check box. I think I am going to to buttons for start and stop. Thanks for the help in advance and look forward to hearing from you. Chris Hey guys, first I am new and I don't really know where this goes but I am wanting some help with developing a program that converts Sound (Speech or more preferably a sound... Like a frequency) to a Keystroke or code.. I know a little bit of C++ if that helps.. (I also Have Visual Studio 2013) Thanks guys
Reply With Quote 12-21-2014, 12:36 PM #2 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts Not possible using Javascript. The Warrington players can hang their heads high. - Commentator, BBC Radio 2 hi there, im trying to get a sound effect to play when a slideshow runs. the user selects the sound from a drop down menu on each image. The sound play when selected. But i need some way to pass it into the function that starts the slideshow. I am using pixtastic library to add effects to the images, and jquery (with cycle plugin) to perform the slideshow. The sounds ive put in work when selected, but i need to write a function to play them when the slideshow runs (this is where im stuck!) The library is soundmanager2 Here is the code Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" src="js/pixastic.core.js"></script> <script type="text/javascript" src="js/pixastic.jquery.js"></script> <script type="text/javascript" src="js/actions/sepia.js"></script> <script type="text/javascript" src="js/actions/flipv.js"></script> <script type="text/javascript" src="js/actions/emboss.js"></script> <script type="text/javascript" src="js/actions/blur.js"></script> <script type="text/javascript" src="js/actions/solarize.js"></script> <script type="text/javascript" src="js/actions/edges.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <!-- include Cycle plugin --> <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script> <script type="text/javascript" src="js/Soundmanager/script/soundmanager.js"></script> <script> function change_image(id, effect) { Pixastic.process(document.getElementById(id),effect); } function startShow() { //get the canvas elements on the page var canvases = document.getElementsByTagName("canvas"); var viewpane = document.getElementById("slideshow"); for(i=0;i<canvases.length;i++) { viewpane.appendChild(canvases[i]); } $('#slideshow').cycle({ fx: 'all' // choose your transition type, ex: fade, scrollUp, shuffle, etc... }); } </script> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="css/main.css" type="text/css" /> <title>My Slideshow</title> </head> <body> <div> <!-- soundManager appends "hidden" Flash to the first DIV on the page. --> </div> <div class="wrap"> <h1 id="logo"><a href="javascript:location.reload(true)">My Slideshow!</a> <br /></a></h1> <ul id="menu"> Welcome to my slideshow, click view show to start<p>alternatively, click the headline to start again</p> </ul> <div id="text"> <h2>Edit the images and start the show!</h2><p><h3>You can add more than one effect to each image!</h3> <div id = "slideshow"> <iNPUT TYPE=BUTTON OnClick="startShow()" VALUE="View The Show"> </div> </div> <div id="leftcolumn"> <div id ="firstImage"> <img id="image1" src = "images/image1.jpg"></image> <form name="first_pic" id="first_pic"> <select name="image1" onchange = "change_image(this.name,this.value);"> <option value="blank">Edit the Image</option> <option value="sepia">Sepia</option> <option value="flipv">Flip Vertical</option> <option value="emboss">Emboss</option> <option value="solarize">Solarize</option> <option value="blur">Blur</option> <option value="edges">Edged</option> </select> <select name="image1" onchange = "soundManager.play(this.value);"> <option value="">Choose a sound</option> <option value="beep">Beep</option> <option value="gangsta">Gangsta</option> <option value="glass">Glass</option> <option value="page">Page turn</option> </select> </div> </p> </div> <div id="rightcolumn"> <div id = "secondImage"> <img id="image2" src = "images/image2.jpg"></image> <form name="first_pic" id="first_pic"> <select name="image2" onchange = "change_image(this.name,this.value);"> <option value="blank">Edit the Image</option> <option value="sepia">Sepia</option> <option value="flipv">Flip Vertical</option> <option value="emboss">Emboss</option> <option value="solarize">Solarize</option> <option value="blur">Blur</option> <option value="edges">Edged</option> </select> <select name="image2" onchange = "soundManager.play(this.value);"> <option value="">Choose a sound</option> <option value="beep">Beep</option> <option value="gangsta">Gangsta</option> <option value="glass">Glass</option> <option value="page">Page turn</option> </select> </div> </div> <div id="green_bubble"> </div> </div> <div id="footer"> <div class="wrap"> <div id="bubble"></div> <div id="copyright"> </div> <div class="clear"></div> </div> </div> <script type="text/javascript">soundManagerInit();</script> </body> </html> Thanks! Which is the best way to play sound using javascript in a controlled manner ? I need a solution which work across all browsers. This is for my bingo game page which is fully based on ajax. Thanks . Ok, I'm working in dreamweaver cs4 I'm trying to make my links have a sound on mouseover. The tag for this is under the depreciated behaviour section. I tried it to test it. It added the following code to my link: Code: To View Full Product Line<br /> <a href="http://herbal-nutrition.net/yesifeelgood/products" target="_blank" onmouseover="MM_controlSound('play','document.test','sounds/Sound 378.mp3')">Click Here</a> <embed name="test" src="sounds/Sound 378.mp3" loop="false" autostart="false" hidden="true" width="0" height="0" enablejavascript="true"></embed> My only problem is that when this loads in a browser on mouseover it loads the window as a quicktime sound then directs to the link preview on the following link (the link where I added the sound is underneath the slideshow: http://www.designfoxmediaworks.com/c...e/carlene.html is there something i should be changing to make this work properly? How can I play a sound when I click an image, without the information bar popping up at top? I've looked all over, and I've tried a few javascript-only methods but none have worked for me.. Is flash the only way to go?
Is it possible to play a sound file when a visitor to my website moves their mouse/pointer over a single image no matter what browser they are using? Thanks for any help or advice.
What is the correct code to make a sound play every time you click a certain image? All the codes I've found online aren't working, or I'm not inputting something correctly..
Please help, I have a page with 3 images. I want my visitors to hear an mp3 audio once they hover their mouse on each image. image1 = audio1.mp3 image2 = audio2.mp3 image3 = audio3.mp3 But here are the challenges. 1- I want the audio files to play on the same page where the images are, without opening a new page. 2- I don't want the users to be asked to accept any kind of plugins (such as Windows Media Player). Which means everything needed to run the script should already exist on that page. 3- I want it to be played on the 3 major browsers (IE, Firefox, Chrome) Is this possible? I'm not good at Javascript, but I will understand to do my best to understand your instructions. I spent a long time looking online, but most of what I found is only compatible in one browser or the other. Any help would be appreciated. I have a self project I am exploring. I would like to play a simple sound file each time a function is run. The function runs every second, so, basically, I am just trying to get an audible click sound file to run every time the function runs. I do not know how to play a sound file thru javascript. Any ideas? Here is the code file thus far... Code: <html> <head> <title>Timer</title> <link href="timer.css" rel="stylesheet" type="text/css" /> <embed src="click.wav" autostart=false hidden=true name="sound1" enablejavascript="true"> <script type="text/javascript"> var seconds = 0; var clockId; var running = false; function runClock() { seconds++; document.timer.timerClock.value = seconds; } function startClock() { if (!running) { clockId = setInterval('runClock()',1000); running = true; } } function stopClock() { if (running) { clearInterval(clockId); running = false; } } function resetClock() { document.timer.timerClock.value = 0; seconds = 0; } </script> </head> <body> <form id="timer" name="timer" action=""> <div id="header"> <p> <span>Timer<br /> </p> </div> <div id="intro"> <p>Click to begin timer</p> <p id="buttons"> <input onclick="startClock()" type="button" value="Begin Seconds Counter" /> <br /> <input name="timerClock" id="timerClock" value="0" /> <br /> <input onclick="stopClock()" type="button" value="Stop Timer" /> <br /> <input onclick="resetClock()" type="button" value="Reset Timer" /> </p> </div> </form> </body> </html> I would like to play a .wav sound file when someone hovers their mouse/pointer over an image. Could someone help me out here please. I am running a Linux OS. Thanks.
Just so you know: this is not my idea, the person whose site this is wants a short blip sound played whenever you roll over the links in the sidebar. I know it's not advised, but she insists. So can anybody tell me how this is done? I've tried implementing a few scripts but no luck in Firefox or Chrome. Thanks. hi i have the following code which works fine in IE but nothing happens in firefox. Code: <html> <bgsound id="sound"> <script> function PlaySound(url) { document.all.sound.src = url; } </script> <body> <a href="#"><img src="images/butters.jpg" onMouseOver="PlaySound('http://www.pacdv.com/sounds/sounds/sound38.mp3')" /></a> </body> </html> Any one know of any good ways to make sound work in firefox? ta I have an on/off image piece of code: (probably out of date!) Code: <!-- var NN3 = false; image1= new Image(); image1.src = "photo1.gif"; image1on = new Image(); image1on.src = "photo2.gif"; function on3(name) { document[name].src = eval(name + "on.src"); } function off3(name) { document[name].src = eval(name + ".src"); } NN3 = true; function on(name) { if (NN3) on3(name); } function off(name) { if (NN3) off3(name); } // --> My problem is that I am trying to add sound to the clicking and mousing out of the image. Without sound, it works (and works exactly the way I want it to) like this; Code: <a href="javascript:myVoid()" onmousedown="on('image1');" onmouseover="off('image1')"> <img src="photo1.gif" name="image1"></a> Adding (flash)sound I can do this and it works OK too: Code: <a href="javascript:myVoid()" onmousedown="on('image1');mySoundObj1.TGotoAndPlay('/go','start'); return true;" onmouseout="off('image1');"> <img src="photo1.gif" name="image1"></a> But what I want to occur is that a second "swish" sound happens onmouseout (in the red place below) but ONLY if the mousedown has already occurred: Code: <!-- ... function on(name) { if (NN3) on3(name); } function off(name) { [SWISH SOUND HERE] if (NN3) off3(name); } // --> I hope this doesn't read complicated. I know it's really a simple toggle with an if, but I've tried dozens of things to no avail. I have to replicate this many hundreds of times in a website...and I have to stick with flashsound (which I like anyway). Any help would be appreciated. Working on a simple JS/jQuery-driven game where the user clicks on a cup to see if it is a winner or not. If so, it plays a happy sound; if not, it plays a sad sound. Everything is working great so far, except for the sound. The html is being set correctly when a cup is selected, but Firebug is telling me the sound files are undefined. Same when I enter the function: playSound("[filename].WAV") in the console. Any help or advice is greatly appreciated. Code: var cupRaised = false; var winningCup; function determineWinner(raisedCup){ if(raisedCup == winningCup){ playSound("applause.WAV"); } else { playSound("sad-trombone.WAV"); } } function playSound(file){ $('#sound_element').html("<embed src='file/"+file+"' hidden='true' autostart='true' loop='false' />"); } function raiseCup(num){ if(!cupRaised){ var cur = "#cup" + num.toString(); $(cur).animate({"top": "-=100px"}, "slow"); cupRaised = true; determineWinner(num); } } |