简体   繁体   中英

Audio is not working when it is included inside another PHP file

I have a PHP file with an audio tag that works just fine when executed. It is like this:

<?php
  echo"<audio controls>";
  echo"<source src='victory.mp3' type='audio/mp3'>";
  echo"</audio>";   
?>

The HTML file with the same functionality works well when executed. However I need to include this file in another PHP file inside a function. Like this:

function play_music()
{
  include('temp.php');
}

Running the above code just gives an audio player, but it won't start as the audio length is shown as 00:00 . Can anyone tell me why this is happening?

I've tested in Chrome, IE and Firefox and the audio tag is compatible with these versions. Any sort of help would be appreciated.

I'm testing your above mention code it's working fine just check this.
temp.php code

<?php echo"<audio controls> <source src='Valentines.mp3' type='audio/mp3'> </audio>";   ?>

Function File Code it's also show called function in same file. check your path if your temp file and function file not in same folder give audio path according to function file path. I'm try all file with same folder.

<?php function play_music(){ include('temp.php'); } echo play_music(); ?>

if your audio file save in same folder where store temp.php and function file is an other folder you use audio file path according to function file path. like you have Music folder and that have temp file and audio file and other have function folder where you store all function then you set you audio path like this ../music/vectory.mp3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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