0

I'm using PHP, i want to play sound file when new record added to database but i need to play that sound only once. i try below code with click function & it works

<?php
if(isset($_REQUEST["action"]))
if($_REQUEST["action"] == "play")
{
?>
<embed src="Kalimba.mp3" autostart="true" loop="false" style="width:5px; height:2px;">
<?php
}
?>

When click on play link it start that mp3 file

<a href="sound.php?action=play">Play</a> 
Another Code
  • 3,083
  • 21
  • 23
Arif
  • 1,222
  • 6
  • 29
  • 60
  • `i try below code with click function & it works` - if you have something that works, what do you want our help with? – DaveRandom Mar 14 '12 at 12:59
  • If you're playing it on the client side (in the browser), then your question is actually how to play a sound on a web page. The short answer is there is no way to do so universally. The longer answer is that your best bet is a combination of Flash for desktop computers, plus HTML5 if you want to support mobile devices as well. – MightyE Mar 14 '12 at 13:00
  • @DaveRandom it works but with click function & i need it to play that sond automatically when new record added successfully. I'm trying to make a sound like in ipad when u recieve new email – Arif Mar 14 '12 at 13:02

2 Answers2

2

To play a sound on a website (pretty universally), you'll want to look into sound manager 2: http://www.schillmania.com/projects/soundmanager2/

If you are asking how to know when a new record is added to the database while the visitor is viewing a page (you want live checking and notification), you'll need to use ajax to fetch the highest id (or something to identify the newest record) and compare the unique identifier with javascript to the previous last id. If they do not match, a new record was added and you should trigger playing the sound.

Dutchie432
  • 28,798
  • 20
  • 92
  • 109
0

You cannot autoplay HTML audio on iPad (or any apple iDevice) without the user touching the screen first. That is built in their mobile webkit browser, to reduce network traffic. Check out this question to see a hacky way of doing it: Autoplay audio files on an iPad with HTML5

Community
  • 1
  • 1
Jon Cairns
  • 11,783
  • 4
  • 39
  • 66