Avatar of Panos
PanosFlag for Germany

asked on 

onclick sound

hello experts.
I have found a tutorial for onclick sound but i noticed that there is a little delay between the click and hearing the sound.
How can i solve this problem?
If not is there any other way to make this work in all the browsers without problems?
<script>
function EvalSound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}
</script>
 
<embed src="sounds/click.mp3" autostart=false width=0 height=0 id="sound1"
enablejavascript="true">
<form>
<input type="button" value="Play Sound" onClick="EvalSound('sound1')">
</form>

Open in new window

JavaScriptScripting Languages

Avatar of undefined
Last Comment
Panos
ASKER CERTIFIED SOLUTION
Avatar of Cem Türk
Cem Türk
Flag of Türkiye image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Panos
Panos
Flag of Germany image

ASKER

Hi cem turk.
I have changed the script and left the rest of the code as it is but i have the same result.
Avatar of Cem Türk
Cem Türk
Flag of Türkiye image

is there a link to your page? there is nothing coded to delay the play... maybe your sound file has some silence ?
Avatar of Panos
Panos
Flag of Germany image

ASKER

I'm testing this on my local PC.Could it be because of the settings of the onboard  soundcard.Is this better to use midi files from windows sounds?
Avatar of Cem Türk
Cem Türk
Flag of Türkiye image

i dont think its related with the soundcard maybe its related with mp3 file itself is it large in size?
Avatar of Panos
Panos
Flag of Germany image

ASKER

it is a 3kb mp3 sound file (click) and it is starting from the beginning without silence
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

On my laptop does your code start mp3 playing immediatelly on button click.
Avatar of Panos
Panos
Flag of Germany image

ASKER

Hi Zvonko.
here is the source code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">



Untitled
<script type="text/javascript">
var snd= new Image();
  snd.src="click.mp3";
function EvalSound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}
</script>






<form>
<input type="button" value="Play Sound" onClick="EvalSound('sound1')">
</form>




I still have the problem
Avatar of Panos
Panos
Flag of Germany image

ASKER

Hi cem turk.
Because i don't want to left this question opened and because zvonko and you have no problem i will accept the solution.Maybe it will help others with this problem.
regards
Panos
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo