我有这个php文件。单击链接时,无法在链接上方的音频播放器中播放作为链接显示的歌曲。 (请参阅我的帖子底部,以查看页面外观)

我也无法忽略该显示中不是.mp3文件的文件。

有人可以告诉我这是怎么做的吗?我是PHP的新手,所以需要帮助。

<audio id="audio" preload="auto" tabindex="0" controls="" >
<source src="http://miksdev.co.uk/Audio/Professor%20Green%20-%20The%20Green%20Lectures%20Vol%201%282%29/08StayHigh.mp3">
//Your Fallback goes here
</audio>



<ul id="playlist">
<?php

//path to directory to scan
$directory = dirname(__FILE__)."/";

//get all files in specified directory
$files = glob($directory . "*");

//print each file name
foreach($files as $file)
{
 //check to see if the file is a folder/directory
 if(is_file($file))
 {

 if(basename($file)!="list.php"){
  ?>
 <li class="active">
<a href="<?php echo basename($file); ?>"><?php echo basename($file); ?></a><br>
 </li>
  <?php }}}?>
</ul>

上面的文件将以下位置的文件显示为链接

Professor Green The Green Lectures Vol 2

You can see how the page looks at this link

最佳答案

您需要在PHP文件中添加if语句,以丢弃非MP3文件。例如:

if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'php') {...}

您的JavaScript代码存在的问题是您过早调用init()函数。等待页面加载完毕并调用它。

您应该添加
<script type="text/javascript">
    init();
</script>

在页面底部(</body>之前),然后删除audio with playlist.js文件中的一个。

09-25 18:29
查看更多