php - 音频播放器 : Load random song from database table without repeating

标签 php mysql database audio html5-audio

我的音频播放器 ( http://www.vegapohl.com/audio ) 有问题。我试图让播放器播放 mysql 数据库中的随机轨道,但我不希望它播放上一首歌曲。只有听完或跳过所有歌曲后,它才会“重置”并再次播放所有轨道。

这是我的 PHP:

<?php
mysql_connect("localhost", "db57276_11", "*****")or die("cannot connect"); 
mysql_select_db(db57276_11)or die("cannot select DB");


$sql = "SELECT * FROM audio ORDER BY RAND()";
$result = mysql_query($sql);
if (false === $result) {
    echo mysql_error();
}
$row = mysql_fetch_row($result);
$url = $row[0];
$title = $row[1];
$artist = $row[2];
$albumart = $row[3];
?>

我在 stackoverflow 上找到了一些类似问题的答案,但没有一个对我有用。为了让您更好地了解一般功能,以下是正文标记:

<body>
<script type="text/javascript">
function playPause(soundId,getImg) {
setTimeout(swapImg,30000,getImg);
soundId.volume=.5;
 if (soundId.paused){
     soundId.play();       
 getImg.src='pause.png';


}
   else {
       soundId.pause();
        getImg.src='play.png';
   }

}

function swapImg(getImg){
getImg.src='play.png';
}
</script>
<div class="wrapper">
<div class="wrapmiddle">
    <div class="middle">

        <div class="track">
            <h1><?php echo $title; ?></h1>
            <h2><?php echo $artist; ?></h2>
            <div id="buttons">
<a href="javascript:window.location.reload()" class="next">Skip</a>
<a href="#"class="like">Share</a><a href="#" class="view">Visit Site</a>
</div>
</div>
</div>
</div>

<div class="left">
<div>
    <audio id="track1" onended = "window.location.reload()">
    <source src="<?php echo $url; ?>" type="audio/mp3"></source>
    Your browser does not support this content.</audio>
    <a href="#" onClick="playPause(track1,playImg1);">
<img alt="" class="playImg"    src="play.png" style="cursor: pointer;" name="playImg1" />   
</a><br />
</div>
</div>
  <div class="right">
  <div class="overlay"><img src="icon.png" width="35" height="34" /> </div>
</div>
</div>
</body>

也许有人知道播放下一首轨道的更好方法(而不是刷新页面/iframe)。如果它可以按顺序播放表中的每个轨道,然后再次从顶部开始,这也可以。希望有人能帮助我解决这个问题。

最佳答案

向您的 SQL 表添加一个额外的smallint 字段,例如status。在该商店中,1 或 0(或您设计的其他内容)表示未播放/未跳过,或已播放/跳过。在 SQL 查询中,添加一个 where 子句,类似于 SELECT Songname,artist,filelocation,status FROM audio WHERE status=0 ORDER BY rand()

关于php - 音频播放器 : Load random song from database table without repeating,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13289563/

相关文章:

c# - 如何进行在其安装的程序中输入的设置?

php - 使用 tcpdf 创建 PDF 在 iphone 上显示空白

php - Mac Mini 中 Laravel 安装错误

mysql - mysql 搜索域,没有 TLD 扩展名

mysql - 允许任何 MAC 管理员用户在启动时运行 MySQL 服务器

php - CodeIgniter 数据库 session 错误

php - mysql - 更新列中的值,同时使所有其他值均为 false

PHP 随机 URL 名称(短 URL)

mysql - 使用单个查询更新两个表

database - 使用 JPA 改变数据库设计