3

这是一个适合办公室工作人员的小包装。我正在尝试开发一个php应该mp3在服务器上运行歌曲并将当前歌曲的歌词(仅)发送到客户端的应用程序。我需要在服务器中随机播放歌曲列表,并且当前歌曲的歌词(在服务器上运行)应该在客户端发送。为此,我做了以下事情(所有事情都在 localhost 中完成)::

  database name:album
  table name: song(id,name,lyrics,status)
  Note: this is manual update done by admin::
  filename: - admin.php
  $id = $_POST['id'];
  mysqli_query($con,"update album set status=0");//all song status cleared
  mysqli_query($con,"update album set status=1 where id=$id");//status with value 1 is playing on               server

文件名:-client.php

<html>
    <meta http-equiv="refresh" content="1" >
    <body align="center" bgcolor="skyblue">
    <?php
    $con=mysqli_connect("localhost","root","root","test");
    // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    //echo $id;
    $result = mysqli_query($con,"select name,lyrics from album where album.status=1");
    //echo last_query();die;
    while($row = mysqli_fetch_array($result))
    {
        echo "<h1>".$row['name']."</h1>";
        echo "<br />";
        echo "<h3>".$row['lyrics']."</h3>";
    }
    mysqli_close($con);
    ?>
    </body>
</html>

现在,上面的代码一切正常,但管理员应该在每次服务器播放歌曲时更新。我需要这个任务自动化。为此,我需要在客户端播放要播放的歌曲列表(来自数据库)及其对应的歌词。该怎么办??提前致谢!!

4

1 回答 1

0

我认为这就是您想要的(它使用 mp3 播放器 mpg123,但您可以使用其他任何东西(cvlc、mplayer、...):

<?php
set_time_limit(0);
$con=mysqli_connect(...);
// Check connection
if (mysqli_connect_errno()){
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
while(true){
  mysqli_query($con,"update album set status=0");
  $res = mysqli_query($con,"select id, file from album order by rand() limit 1");
  $row = mysqli_fetch_assoc($res);
  mysqli_query($con,"update album set status=1 where id=".$row['id']);
  passthru('mpg123 '.escapeshellarg($row['file']));
}

此脚本旨在从命令行执行(而不是使用 Web 服务器)

于 2013-03-02T21:30:09.427 回答