Jimmy12 Posted October 21, 2020 Share Posted October 21, 2020 Hi, i have the following code: where i want the sound to only play during the false part of the IF statement but currently it always plays on every reload, and even if the IF = true any ideas? ive tried autoplay="0" also Thanks <embed src="beep.wav" autostart="false" width="0" height="0" id="sound1" enablejavascript="true"> + <script> function PlaySound(soundObj) { var sound = document.getElementById(soundObj); sound.Play(); } </script> + if( isset( $json['Data'] ) ){ echo "<b>Success</b>"; echo "</br>"; echo $data.' x ' .$tqty; echo "</br>"; } else { echo "Error"; echo "</br>"; echo $json['Message']; echo '<script> PlaySound("Sound1"); </script>'; } Quote Link to comment https://forums.phpfreaks.com/topic/311621-embedded-audio-file-always-plays-on-load-even-with-autoplay-off/ Share on other sites More sharing options...
gw1500se Posted October 21, 2020 Share Posted October 21, 2020 It is playing because you are telling it to in the echo/script. If you want the user to start the play, create a button instead and have the onClick attribute execute the PlaySound script. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311621-embedded-audio-file-always-plays-on-load-even-with-autoplay-off/#findComment-1581982 Share on other sites More sharing options...
requinix Posted October 21, 2020 Share Posted October 21, 2020 <embed> is so 1990s. Use <audio>. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311621-embedded-audio-file-always-plays-on-load-even-with-autoplay-off/#findComment-1581985 Share on other sites More sharing options...
Jimmy12 Posted October 21, 2020 Author Share Posted October 21, 2020 2 hours ago, gw1500se said: It is playing because you are telling it to in the echo/script. If you want the user to start the play, create a button instead and have the onClick attribute execute the PlaySound script. yes though the echo/script should only run when the 2nd part of the IF statement is initiated. I dont want the user to start anything - more of an alert when an error occurs Quote Link to comment https://forums.phpfreaks.com/topic/311621-embedded-audio-file-always-plays-on-load-even-with-autoplay-off/#findComment-1581986 Share on other sites More sharing options...
Jimmy12 Posted October 21, 2020 Author Share Posted October 21, 2020 6 minutes ago, requinix said: <embed> is so 1990s. Use <audio>. doesnt this add the audio player though ? Quote Link to comment https://forums.phpfreaks.com/topic/311621-embedded-audio-file-always-plays-on-load-even-with-autoplay-off/#findComment-1581987 Share on other sites More sharing options...
requinix Posted October 21, 2020 Share Posted October 21, 2020 22 minutes ago, Jimmy12 said: doesnt this add the audio player though ? Not if you don't show the controls. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311621-embedded-audio-file-always-plays-on-load-even-with-autoplay-off/#findComment-1581988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.