Skip to content

Commit

Permalink
wip fixing spotify bug
Browse files Browse the repository at this point in the history
  • Loading branch information
klay2000 committed Oct 3, 2022
1 parent 7319c9c commit 9e90f70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 13 additions & 2 deletions amplipi/mpris.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from enum import Enum, auto
import json
import time
import os
import sys
from typing import List
from multiprocessing import Process, set_start_method
from multiprocessing import Process
from dasbus.connection import SessionMessageBus


Expand Down Expand Up @@ -133,6 +135,7 @@ def get_capabilities(self) -> List[CommandTypes]:
def __del__(self):
try:
self.metadata_process.kill()
os.wait() # does this work?
except Exception as e:
print(f'Could not stop MPRIS metadata process: {e}')

Expand All @@ -151,8 +154,14 @@ def _metadata_reader(self):
last_sent = m.__dict__

while True:
print("getting metadata")
try:
raw_metadata = mpris.Metadata
raw_metadata = {}
try:
raw_metadata = mpris.Metadata
except Exception as e:
print(f"Dbus error getting MPRIS metadata: {e}")

metadata = {}

for mapping in METADATA_MAPPINGS:
Expand All @@ -171,4 +180,6 @@ def _metadata_reader(self):
except Exception as e:
print(f"Error writing MPRIS metadata to file at {self.metadata_path}: {e}\nThe above is normal if a user is not yet connected to Spotifyd.")

sys.stdout.flush() # forces stdout to print

time.sleep(1.0/METADATA_REFRESH_RATE)
6 changes: 4 additions & 2 deletions amplipi/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ def connect(self, src):
except Exception as exc:
print(f'Error starting Spotifyd: {exc}')

time.sleep(0.1) # Delay a bit
time.sleep(0.25) # Delay a bit

try:
self.mpris = MPRIS(f'spotifyd.instance{self.proc.pid}', f'{src_config_folder}/metadata.txt')
except Exception as exc:
print(f'Error starting spotify MPRIS reader: {exc}')

self._connect(src)
self._connect(src)


def disconnect(self):
Expand All @@ -302,6 +302,8 @@ def disconnect(self):
self._disconnect()
self.connect_port = None
del self.mpris # garbage collection doesn't kill this fast enough
del self.proc
time.sleep(0.1)
self.mpris = None
self.proc = None

Expand Down

0 comments on commit 9e90f70

Please sign in to comment.