![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/.cursor-server/data/User/History/-4c530bc6/ |
<?php
/**
* Update now playing track
*/
$data = json_decode(file_get_contents('php://input'), true);
if (!isset($data['track_id'])) {
http_response_code(400);
echo json_encode(['error' => 'Missing track_id']);
exit;
}
$track_id = (int)$data['track_id'];
// Get stream for this station
$stmt = $pdo->prepare("SELECT id FROM radio_streams WHERE station_id = ? AND is_live = TRUE");
$stmt->execute([$station['id']]);
$stream = $stmt->fetch();
if (!$stream) {
http_response_code(400);
echo json_encode(['error' => 'No active stream found']);
exit;
}
// Verify track exists and is radio-enabled
$stmt = $pdo->prepare("SELECT id, duration FROM music_tracks WHERE id = ? AND radio_enabled = 1");
$stmt->execute([$track_id]);
$track = $stmt->fetch();
if (!$track) {
http_response_code(404);
echo json_encode(['error' => 'Track not found or not available for radio']);
exit;
}
// End previous track
$stmt = $pdo->prepare("
UPDATE radio_now_playing
SET ended_at = NOW(),
duration_played = TIMESTAMPDIFF(SECOND, started_at, NOW())
WHERE stream_id = ? AND ended_at IS NULL
");
$stmt->execute([$stream['id']]);
// Create new now playing entry
$stmt = $pdo->prepare("
INSERT INTO radio_now_playing (stream_id, track_id, started_at, listener_count_at_start)
VALUES (?, ?, NOW(), (SELECT listener_count FROM radio_streams WHERE id = ?))
");
$stmt->execute([$stream['id'], $track_id, $stream['id']]);
// Update stream's current track
$stmt = $pdo->prepare("
UPDATE radio_streams
SET current_track_id = ?
WHERE id = ?
");
$stmt->execute([$track_id, $stream['id']]);
// Log the play
logRadioPlay($pdo, $station['id'], $track_id, null, 'full');
// Get now playing details
$stmt = $pdo->prepare("
SELECT np.*, mt.title, mt.audio_url, mt.image_url, mt.duration,
u.name as artist_name
FROM radio_now_playing np
JOIN music_tracks mt ON np.track_id = mt.id
LEFT JOIN users u ON mt.user_id = u.id
WHERE np.id = ?
");
$stmt->execute([$pdo->lastInsertId()]);
$now_playing = $stmt->fetch();
echo json_encode([
'success' => true,
'now_playing' => $now_playing,
'message' => 'Now playing updated'
]);