0

I want too play two audio files using PHP. First file should play first and when it stops the second one should start playing. I have the following code but the problem is that both files are getting played simultaneously and it's really getting mixed up.

<?php
$y = 2;
$z = 3;
$filea = "bflat.mp3";
$fileb = "SUUCgrcp.mp3";
if ($y == 2) {
    echo "<embed src=\"$filea\" hidden=\"true\" autostart=\"false\"></embed>";
} 

if ($z == 3) {
    echo "<embed src=\"$fileb\" hidden=\"true\" autostart=\"false\"></embed>";
}
?>
Antti29
  • 2,953
  • 12
  • 34
  • 36
  • 3
    It's not a PHP problem, it's a HTML problem. You may want to look at this topic: https://stackoverflow.com/questions/31419690/2-audio-sounds-and-i-want-to-play-one-html5-audio-element-at-a-time – juzraai Oct 10 '17 at 08:31
  • PLZ tell ME HOW TO MODIFY THE CODE SO THAT the sound gets played automatically i.e. I dont have to click and the player should be hidden – Vipul Saini Oct 10 '17 at 09:11
  • 1
    https://stackoverflow.com/questions/18274061/html-5-audio-tag-multiple-files look this – Frankich Oct 10 '17 at 09:40

1 Answers1

0

As commented by juzraai, this doesn't have anything with PHP. PHP is typically used to generate the HTML, which JavaScript can manipulate.

You most likely want to use JavaScript to poll for when the first track has finished, to then start the second track.

If you get blocked on that you can always come back with what went wrong and get more help :).

mikey
  • 1,068
  • 10
  • 13
  • would u plz tell me how to do that I am new to coding what changes shd I do in the code – Vipul Saini Oct 10 '17 at 13:36
  • You should at least give that a shot yourself and then if you get stuck ask far more specific questions. i.e. googling 'toggle audio javascript', first result: https://stackoverflow.com/questions/27368778/how-to-toggle-audio-play-pause-with-one-button-or-link – mikey Nov 01 '17 at 06:43