Skip to content

Commit c873aa3

Browse files
authored
Merge pull request #35 from joshuaaaaa/claude/fix-media-playback-stall-pm221
Disable stall detection for Cast devices (Google Mini)
2 parents 611cb96 + 9ceaa06 commit c873aa3

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

radio-browser-card.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,50 +2373,50 @@ class RadioBrowserCard extends HTMLElement {
23732373
this._recoverPlayback();
23742374
return;
23752375
}
2376-
}
23772376

2378-
// Check if playback state indicates playing
2379-
if (entity.state !== 'playing') {
2380-
console.warn('Player state is not "playing", attempting recovery...');
2381-
this._recoverPlayback();
2382-
return;
2383-
}
2377+
// Check if playback state indicates playing
2378+
if (entity.state !== 'playing') {
2379+
console.warn('Player state is not "playing", attempting recovery...');
2380+
this._recoverPlayback();
2381+
return;
2382+
}
2383+
2384+
// For browser players, check if media position is updating (detects silent/stalled playback)
2385+
const mediaPosition = entity.attributes.media_position;
2386+
const mediaDuration = entity.attributes.media_duration;
2387+
2388+
// For live streams (duration is null, 0, or undefined), skip position checks
2389+
// Live streams often report a constant position value (e.g., 0) which doesn't indicate stalling
2390+
const isLiveStream = !mediaDuration || mediaDuration === 0;
23842391

2385-
// For streams, check if media position is updating (detects silent/stalled playback)
2386-
const mediaPosition = entity.attributes.media_position;
2387-
const mediaDuration = entity.attributes.media_duration;
2388-
2389-
// For live streams (duration is null, 0, or undefined), skip position checks
2390-
// Live streams often report a constant position value (e.g., 0) which doesn't indicate stalling
2391-
const isLiveStream = !mediaDuration || mediaDuration === 0;
2392-
2393-
if (isLiveStream) {
2394-
// Live stream - rely on state only, don't check position changes
2395-
this._lastMediaPosition = null;
2396-
this._mediaStallCount = 0;
2397-
} else if (mediaPosition !== undefined && mediaPosition !== null) {
2398-
// Non-live content with position tracking - check for stalls
2399-
if (this._lastMediaPosition !== null && mediaPosition === this._lastMediaPosition) {
2400-
this._mediaStallCount++;
2401-
console.warn(`Media position hasn't changed (${mediaPosition}s) - stall count: ${this._mediaStallCount}`);
2402-
2403-
// If position hasn't changed for 2 checks (40 seconds), consider it stalled
2404-
if (this._mediaStallCount >= 2) {
2405-
console.error('Media playback appears stalled (no position change), forcing recovery...');
2392+
if (isLiveStream) {
2393+
// Live stream - rely on state only, don't check position changes
2394+
this._lastMediaPosition = null;
2395+
this._mediaStallCount = 0;
2396+
} else if (mediaPosition !== undefined && mediaPosition !== null) {
2397+
// Non-live content with position tracking - check for stalls
2398+
if (this._lastMediaPosition !== null && mediaPosition === this._lastMediaPosition) {
2399+
this._mediaStallCount++;
2400+
console.warn(`Media position hasn't changed (${mediaPosition}s) - stall count: ${this._mediaStallCount}`);
2401+
2402+
// If position hasn't changed for 2 checks (40 seconds), consider it stalled
2403+
if (this._mediaStallCount >= 2) {
2404+
console.error('Media playback appears stalled (no position change), forcing recovery...');
2405+
this._mediaStallCount = 0;
2406+
this._lastMediaPosition = null;
2407+
this._recoverPlayback();
2408+
return;
2409+
}
2410+
} else {
2411+
// Position changed, reset stall counter
24062412
this._mediaStallCount = 0;
2407-
this._lastMediaPosition = null;
2408-
this._recoverPlayback();
2409-
return;
24102413
}
2414+
this._lastMediaPosition = mediaPosition;
24112415
} else {
2412-
// Position changed, reset stall counter
2416+
// No position tracking available
2417+
this._lastMediaPosition = null;
24132418
this._mediaStallCount = 0;
24142419
}
2415-
this._lastMediaPosition = mediaPosition;
2416-
} else {
2417-
// No position tracking available
2418-
this._lastMediaPosition = null;
2419-
this._mediaStallCount = 0;
24202420
}
24212421
}
24222422
}

0 commit comments

Comments
 (0)