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.
import os
os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide"
from helpers.os_environment import isLinux
# It's the only one we could get to work.
if isLinux():
@ -34,7 +35,7 @@ import copy
import json
import time
from typing import Any, Callable, Dict, List, Optional
from pygame import mixer
from pygame import mixer, error
from mutagen.mp3 import MP3
from syncer import sync
from threading import Timer
@ -160,7 +161,7 @@ class Player:
@property
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
state["loaded_item"] = (
@ -1054,12 +1055,18 @@ class Player:
self.logger.log.info(
"Seeking to pos_true: " + str(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:
self.logger.log.info("Resuming playback on init.")
# Use un-pause as we don't want to jump to a new position.
try:
self.unpause()
except error:
self.logger.log.error("Failed to unpause on player start. Continuing anyway.")
else:
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)):
try:
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
if source not in ["WEBSOCKET", "ALL"]:
self.logger.log.error(
@ -223,16 +237,14 @@ class WebsocketServer:
)
continue
command = message.split(":")[1]
if command == "STATUS":
try:
message = message.split("OKAY:")[1]
message = json.loads(message)
message = json.loads(data)
except Exception:
continue # TODO more logging
elif command == "POS":
try:
message = message.split(":", 2)[2]
message = data
except Exception:
continue
elif command == "QUIT":