Fix player bootlooping if mixer doesn't init

This commit is contained in:
Matthew Stratford 2021-12-23 19:31:36 +00:00
parent 8b4265a33a
commit ba4e257fdd
2 changed files with 28 additions and 9 deletions

View file

@ -22,6 +22,7 @@
# Stop the Pygame Hello message. # Stop the Pygame Hello message.
import os import os
os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide" os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide"
from helpers.os_environment import isLinux from helpers.os_environment import isLinux
# It's the only one we could get to work. # It's the only one we could get to work.
if isLinux(): if isLinux():
@ -34,7 +35,7 @@ import copy
import json import json
import time import time
from typing import Any, Callable, Dict, List, Optional from typing import Any, Callable, Dict, List, Optional
from pygame import mixer from pygame import mixer, error
from mutagen.mp3 import MP3 from mutagen.mp3 import MP3
from syncer import sync from syncer import sync
from threading import Timer from threading import Timer
@ -160,7 +161,7 @@ class Player:
@property @property
def status(self): def status(self):
state = copy.copy(self.state.state) state = self.state.state
# Not the biggest fan of this, but maybe I'll get a better solution for this later # Not the biggest fan of this, but maybe I'll get a better solution for this later
state["loaded_item"] = ( state["loaded_item"] = (
@ -1054,12 +1055,18 @@ class Player:
self.logger.log.info( self.logger.log.info(
"Seeking to pos_true: " + str(loaded_state["pos_true"]) "Seeking to pos_true: " + str(loaded_state["pos_true"])
) )
self.seek(loaded_state["pos_true"]) try:
self.seek(loaded_state["pos_true"])
except error:
self.logger.log.error("Failed to seek on player start. Continuing anyway.")
if loaded_state["playing"] is True: if loaded_state["playing"] is True:
self.logger.log.info("Resuming playback on init.") self.logger.log.info("Resuming playback on init.")
# Use un-pause as we don't want to jump to a new position. # Use un-pause as we don't want to jump to a new position.
self.unpause() try:
self.unpause()
except error:
self.logger.log.error("Failed to unpause on player start. Continuing anyway.")
else: else:
self.logger.log.info("No file was previously loaded to resume.") self.logger.log.info("No file was previously loaded to resume.")

View file

@ -213,7 +213,21 @@ class WebsocketServer:
for channel in range(len(self.webstudio_to_q)): for channel in range(len(self.webstudio_to_q)):
try: try:
message = self.webstudio_to_q[channel].get_nowait() message = self.webstudio_to_q[channel].get_nowait()
source = message.split(":")[0] msg_split = message.split(":",3)
parts = len(msg_split)
source = msg_split[0]
command = msg_split[1]
if parts == 4:
#status = msg_split[2]
data = msg_split[3]
elif parts == 3:
data = msg_split[2]
else:
self.logger.log.exception(
"Invalid message size:", msg_split
)
continue
# TODO ENUM # TODO ENUM
if source not in ["WEBSOCKET", "ALL"]: if source not in ["WEBSOCKET", "ALL"]:
self.logger.log.error( self.logger.log.error(
@ -223,16 +237,14 @@ class WebsocketServer:
) )
continue continue
command = message.split(":")[1]
if command == "STATUS": if command == "STATUS":
try: try:
message = message.split("OKAY:")[1] message = json.loads(data)
message = json.loads(message)
except Exception: except Exception:
continue # TODO more logging continue # TODO more logging
elif command == "POS": elif command == "POS":
try: try:
message = message.split(":", 2)[2] message = data
except Exception: except Exception:
continue continue
elif command == "QUIT": elif command == "QUIT":