3

This is an small package for an office staffs. I am trying to develop a php application that should run mp3 song on server and send the lyrics of the current song(only) to the client side. I need to play list of songs randomly in server and the lyrics of current song(running on server) should be sent on client side. For this I have done following things(all things are done in 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

filename: - 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>

Now, everything is okay with above code but the admin should update each time which song is playing in server. I need this task automated. For this, i need to play list of songs(from database) to be played and their corresponding lyrics in client side. What to do?? Thanks in advance!!

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 に答える