prevent lots and lots of error spam
This commit is contained in:
@@ -6,6 +6,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Callable, List, Optional
|
from typing import Callable, List, Optional
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
from PySide6.QtCore import QObject, QUrl, Signal
|
from PySide6.QtCore import QObject, QUrl, Signal
|
||||||
from PySide6.QtMultimedia import QAudioOutput, QMediaPlayer
|
from PySide6.QtMultimedia import QAudioOutput, QMediaPlayer
|
||||||
@@ -43,6 +44,11 @@ class PlaybackManager(QObject):
|
|||||||
self._shuffleOrder: List[int] = []
|
self._shuffleOrder: List[int] = []
|
||||||
self._shufflePosition: int = -1
|
self._shufflePosition: int = -1
|
||||||
|
|
||||||
|
# Error debouncing to prevent spawning multiple dialogs for the same error
|
||||||
|
self._lastErrorMessage: str = ""
|
||||||
|
self._lastErrorTime: float = 0.0
|
||||||
|
self._errorDebounceSeconds: float = 2.0
|
||||||
|
|
||||||
self.player.playbackStateChanged.connect(self._handlePlaybackStateChanged)
|
self.player.playbackStateChanged.connect(self._handlePlaybackStateChanged)
|
||||||
self.player.positionChanged.connect(self._handlePositionChanged)
|
self.player.positionChanged.connect(self._handlePositionChanged)
|
||||||
self.player.mediaStatusChanged.connect(self._handleMediaStatus)
|
self.player.mediaStatusChanged.connect(self._handleMediaStatus)
|
||||||
@@ -315,7 +321,22 @@ class PlaybackManager(QObject):
|
|||||||
self.next(fromAuto=True)
|
self.next(fromAuto=True)
|
||||||
|
|
||||||
def _handleError(self, error) -> None:
|
def _handleError(self, error) -> None:
|
||||||
"""Surface player errors to the UI."""
|
"""Surface player errors to the UI with debouncing to prevent dialog spam."""
|
||||||
if error:
|
if not error:
|
||||||
description = self.player.errorString() or str(error)
|
return
|
||||||
self.errorOccurred.emit(description)
|
|
||||||
|
description = self.player.errorString() or str(error)
|
||||||
|
currentTime = time.monotonic()
|
||||||
|
|
||||||
|
# Debounce: skip if same error within debounce window
|
||||||
|
if (description == self._lastErrorMessage and
|
||||||
|
currentTime - self._lastErrorTime < self._errorDebounceSeconds):
|
||||||
|
return
|
||||||
|
|
||||||
|
self._lastErrorMessage = description
|
||||||
|
self._lastErrorTime = currentTime
|
||||||
|
|
||||||
|
# Stop playback to prevent further cascading errors
|
||||||
|
self.player.stop()
|
||||||
|
|
||||||
|
self.errorOccurred.emit(description)
|
||||||
|
|||||||
Reference in New Issue
Block a user