Skip to content

Commit

Permalink
fix(player): Improve HLS stream playback
Browse files Browse the repository at this point in the history
    - Update `mpv` to the last version.
    - Add cache parameters to fix HLS stream playback issues.
    - Add log handler for debugging MPV player issues.
  • Loading branch information
andreztz committed Aug 7, 2024
1 parent 4f49d56 commit 60185e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ pycairo==1.26.0
Pygments==2.18.0
PyGObject==3.48.2
pyradios==2.1.0
python-mpv==1.0.6
python-vlc==3.0.20123
setuptools==70.0.0
sniffio==1.3.1
streamscrobbler3==0.0.4
tinydb==4.8.0
wcwidth==0.2.13
mpv==1.0.7
20 changes: 17 additions & 3 deletions xradios/core/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class PlayerBase(ABC):

state = False

@abstractmethod
Expand All @@ -35,9 +34,24 @@ def playing(self):
return self.state


class MPVPlayer(PlayerBase):
def log_handler(level, prefix, message):
func = getattr(log, level.lower(), log.info) # getattr default -> log.info
func(f"{prefix}: {message}")

player = MPV()

class MPVPlayer(PlayerBase):
extra_mpv_opts = {
"cache": True,
"cache_secs": 10,
}

player = MPV(
log_handler=log_handler,
loglevel=logging.getLevelName(log.root.level).lower(),
**extra_mpv_opts,
)
log.debug(f"mpv --cache ---> {player['cache']}")
log.debug(f"mpv --cache-secs ---> {player.cache_secs}")

def play(self, stationuuid):
url = self._click_counter(stationuuid)
Expand Down

0 comments on commit 60185e0

Please sign in to comment.