简体   繁体   English

页内声音警告

[英]in-page acoustic warnings

I need to create an acoustic warning in a PHP backed page that plays when certain conditions in PHP are met. 我需要在PHP支持的页面中创建声音警告,该页面在满足PHP中的某些条件时播放。

The only way of how to do this I can think of is conditional embedding of a small flash file that would play the sound upon rendering in browser... However, this seems as a bit out of date practice to me... Something like the JS alert() sound would be sufficient (I have considered using the alert() way too). 如何做到这一点的唯一方法我可以想到的是条件嵌入一个小的flash文件,它会在浏览器中渲染时播放声音...但是,这对我来说似乎有些过时的练习......有点像JS alert()声音就足够了(我也考虑过使用alert()方式)。 Or the Facebook chat message notification sound... 或Facebook聊天消息通知声音......

Any other ideas how this could be done? 还有其他想法如何做到这一点? Preferably using jQuery / JS etc... 最好使用jQuery / JS等...

(not looking for any complete solution / code etc, just point me in the right direction... if there is any) (不寻找任何完整的解决方案/代码等,只需指出我正确的方向......如果有的话)

HTML5 audio element HTML5音频元素

<audio src="audio.ogg" controls autoplay loop>
     <p>Your browser does not support the audio element </p>
</audio>

Popular JS library is SoundManager2 流行的JS库是SoundManager2

Add this to your js when the condition you want is met : 当满足您想要的条件时,将其添加到您的js:

var snd='<audio autoplay="true"><source src="sound.mp3"></audio>';  
$('body').append(snd);

I had the same problem and simply I used this: 我有同样的问题,我只是用这个:

if($condition)
  echo "<embed src='/file/sound/alert.swf' />"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM