简体   繁体   English

当音频包含在另一个PHP文件中时,音频不起作用

[英]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. 我有一个带有audio标签的PHP文件,该文件在执行时效果很好。 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. 具有相同功能的HTML文件在执行时效果很好。 However I need to include this file in another PHP file inside a function. 但是,我需要将此文件包含在函数内的另一个PHP文件中。 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 . 运行上面的代码仅提供了一个audio播放器,但由于音频长度显示为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. 我已经在Chrome,IE和Firefox中进行了测试,并且audio标签与这些版本兼容。 Any sort of help would be appreciated. 任何形式的帮助将不胜感激。

I'm testing your above mention code it's working fine just check this. 我正在测试上述代码,请检查此代码是否正常。
temp.php code temp.php代码

<?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. 如果您的音频文件保存在同一文件夹中,其中temp.php和功能文件是另一个文件夹,则您将根据功能文件路径使用音频文件路径。 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 像您有“音乐”文件夹,有临时文件和音频文件,以及其他有“功能”文件夹,在其中存储所有功能,然后将音频路径设置为../music/vectory.mp3

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

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