fix: cache bust radio streams on play

This commit is contained in:
2025-10-13 10:11:33 +03:00
parent 60fc457139
commit 5cf17f881a
2 changed files with 21 additions and 5 deletions

View File

@@ -364,12 +364,16 @@ class RadioController extends OCSController {
}
try {
$stream = @fopen($streamUrl, 'rb');
// Add cache-busting to the stream URL to prevent server-side caching
$separator = strpos($streamUrl, '?') !== false ? '&' : '?';
$cacheBustedUrl = $streamUrl . $separator . '_t=' . time();
$stream = @fopen($cacheBustedUrl, 'rb');
if (!$stream) {
throw new \RuntimeException('Unable to open stream');
}
$headers = @get_headers($streamUrl, true);
$headers = @get_headers($cacheBustedUrl, true);
$contentType = is_array($headers) && isset($headers['Content-Type'])
? (is_array($headers['Content-Type']) ? $headers['Content-Type'][0] : $headers['Content-Type'])
: 'audio/mpeg';
@@ -379,8 +383,10 @@ class RadioController extends OCSController {
Http::STATUS_OK,
[
'Content-Type' => $contentType,
'Cache-Control' => 'no-store, must-revalidate',
'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0',
'Pragma' => 'no-cache',
'Expires' => '0',
'X-Accel-Buffering' => 'no',
'Content-Transfer-Encoding' => 'binary',
]
);

View File

@@ -65,7 +65,15 @@ function getStreamUrl(media: Playable): string {
if (!pathResolver) {
throw new Error(`Unsupported media type: ${media.type}`)
}
return axios.defaults.baseURL + pathResolver(media)
const baseUrl = axios.defaults.baseURL + pathResolver(media)
// Add cache-busting for radio streams to ensure fresh content
if (media.type === 'radio') {
const separator = baseUrl.includes('?') ? '&' : '?'
return `${baseUrl}${separator}_t=${Date.now()}`
}
return baseUrl
}
function trackAction(media: Playable, action: 'play' | 'pause' | 'complete' | 'resume') {
@@ -133,7 +141,9 @@ async function playMedia(media: Playable) {
const src = getStreamUrl(media)
if (audio.src !== src) {
// For radio streams, always reload to get fresh content
// For other media types, only reload if the source changed
if (audio.src !== src || media.type === 'radio') {
audio.pause()
resumePosition.value = await getStartPosition(media)
audio.src = src