Пример #1
0
function streamPlay($id, $rate = 0, $stereo = "s", $user = '', $ip = '')
{
    mp3act_connect();
    // check to see if IP is in the verified IP DB for that user
    if (verifyIP($user, $ip)) {
        $query = "SELECT mp3act_artists.artist_name, \n  mp3act_songs.name,\n  mp3act_songs.bitrate, \n  mp3act_songs.length as length, \n  mp3act_songs.filename as filename, \n  mp3act_songs.size as size \n  FROM mp3act_songs,mp3act_artists \n  WHERE mp3act_songs.song_id={$id} \n  AND mp3act_artists.artist_id=mp3act_songs.artist_id";
        $result = mysql_query($query);
        $row = mysql_fetch_array($result);
        updateNumPlays($id, 0, $user, 'streaming');
        clearstatcache();
        // flush buffer
        $file['name'] = basename($row['filename']);
        $mp3out = '';
        if (getSystemSetting("lamebin") != "" && $rate != 0) {
            $row['size'] = ($row['length'] + 1) * $rate * 1000 / 8;
            $mp3out = getSystemSetting("lamebin") . " -b {$rate} -s {$stereo} --silent --nores --mp3input -h \"" . stripslashes($row['filename']) . "\" -";
        } else {
            $mp3out = stripslashes($row['filename']);
        }
        $size = $row['size'];
        $mode = getSystemSetting("sample_mode");
        if ($mode == 1) {
            $size = floor($row['size'] / 4);
        }
        header("Content-Type: audio/mpeg");
        header("Content-Length: {$size}");
        header("Content-Disposition: filename={$row['artist_name']} - {$row['name']}");
        // Run the command, and read back the results at the bitrate size + 1K.
        $blocksize = $row['bitrate'] * 1024 + 1024;
        $totaldata = 0;
        if ($rate != 0 && $mode == 1) {
            $temp = @popen($mp3out, "r");
            while (($data = @fread($temp, $blocksize)) && $totaldata <= $size) {
                echo $data;
                $totaldata += $blocksize;
            }
            pclose($temp);
        } elseif ($rate != 0) {
            $temp = @popen($mp3out, "r");
            while ($data = @fread($temp, $blocksize)) {
                echo $data;
            }
            pclose($temp);
        } elseif ($mode == 1) {
            $temp = @fopen($mp3out, "r");
            while (!feof($temp) && $totaldata <= $size) {
                $data = @fread($temp, $blocksize);
                echo $data;
                $totaldata += $blocksize;
            }
            fclose($temp);
        } else {
            $temp = @fopen($mp3out, "r");
            while (!feof($temp)) {
                $data = @fread($temp, $blocksize);
                echo $data;
            }
            fclose($temp);
        }
    }
    // end IF for verify IP
    exit;
}
Пример #2
0
        } else {
            $row = mysql_fetch_array($result);
            $query = "DELETE FROM mp3act_currentsong";
            mysql_query($query);
            updateNumPlays($row['song_id'], 1, $_SERVER['argv'][2]);
            setCurrentSong($row['song_id'], 0, 1);
            playLocal($row['filename']);
        }
    }
    $query = "DELETE FROM mp3act_currentsong";
    mysql_query($query);
    if (file_exists("/tmp/mp3act")) {
        unlink("/tmp/mp3act");
    }
} else {
    while (1) {
        $query = "SELECT song_id,filename FROM mp3act_songs WHERE random!=1 ORDER BY rand()+0 LIMIT 1";
        $result = mysql_query($query);
        $row = mysql_fetch_array($result);
        $query = "DELETE FROM mp3act_currentsong";
        mysql_query($query);
        updateNumPlays($row['song_id'], 1, $_SERVER['argv'][2]);
        setCurrentSong($row['song_id'], 0, 1);
        playLocal($row['filename']);
    }
    $query = "DELETE FROM mp3act_currentsong";
    mysql_query($query);
    if (file_exists("/tmp/mp3act")) {
        unlink("/tmp/mp3act");
    }
}