fix lights in sync

This commit is contained in:
j 2023-10-12 11:38:34 +01:00
parent d0f0184deb
commit 10faed82e4
4 changed files with 13 additions and 16 deletions

View file

@ -5,7 +5,6 @@ import os
import time import time
import ox import ox
import lanbox
import sacn import sacn
from .pi import random from .pi import random
@ -103,6 +102,7 @@ def fade_to(target, duration):
def switch(state): def switch(state):
lights, duration = LIGHTS[state] lights, duration = LIGHTS[state]
if config.lanbox: if config.lanbox:
import lanbox
lb = lanbox.Lanbox() lb = lanbox.Lanbox()
#lb.getChannels(lights) #lb.getChannels(lights)
#lb.fadeTo(lights, fade) #lb.fadeTo(lights, fade)

View file

@ -4,7 +4,7 @@ from glob import glob
import os import os
import sys import sys
from .utils import update_playlist, get_player, trigger_lights from .utils import update_playlist, get_player, trigger_lights, get_path
from .subtitleserver import SubtitleServer from .subtitleserver import SubtitleServer
from . import config from . import config
@ -22,11 +22,6 @@ def q_binding(*args):
player = None player = None
def get_path(path):
if isinstance(path, bytes):
path = path.decode()
return path
def main(): def main():
global player global player

View file

@ -13,7 +13,8 @@ from queue import Queue
from socketserver import UDPServer, ThreadingMixIn, BaseRequestHandler from socketserver import UDPServer, ThreadingMixIn, BaseRequestHandler
from threading import Thread from threading import Thread
from .utils import update_playlist, get_player, trigger_lights from .utils import update_playlist, get_player, trigger_lights, get_path
from . import config
import logging import logging
logger = logging.getLogger('cdosea') logger = logging.getLogger('cdosea')
@ -55,12 +56,11 @@ class Player(Thread):
current = '' current = ''
playlist_items = 260 playlist_items = 260
def __init__(self, peer, player, playlist, prefix, lights=False): def __init__(self, peer, player, playlist, prefix):
self.peer = peer self.peer = peer
self.playlist = playlist self.playlist = playlist
self.prefix = prefix self.prefix = prefix
self.player = player self.player = player
self.lights = lights
self.queue = Queue() self.queue = Queue()
Thread.__init__(self) Thread.__init__(self)
self.daemon = True self.daemon = True
@ -84,8 +84,8 @@ class Player(Thread):
def play(self): def play(self):
self.playing = True self.playing = True
self.player.pause = False self.player.pause = False
if self.lights: if config.lights and self.player.path:
trigger_lights(self.player.path.decode()) trigger_lights(get_path(self.player.path))
self.player.wait_for_playback() self.player.wait_for_playback()
self.player.pause = True self.player.pause = True
self.playing = False self.playing = False
@ -128,7 +128,6 @@ def main():
parser.add_argument('--prefix', help='video location', default=prefix) parser.add_argument('--prefix', help='video location', default=prefix)
parser.add_argument('--window', action='store_true', help='run in window', default=False) parser.add_argument('--window', action='store_true', help='run in window', default=False)
parser.add_argument('--debug', action='store_true', help='debug', default=False) parser.add_argument('--debug', action='store_true', help='debug', default=False)
parser.add_argument('--lights', action='store_true', help='lights', default=False)
args = parser.parse_args() args = parser.parse_args()
if ':' in args.peer: if ':' in args.peer:
@ -143,13 +142,11 @@ def main():
logging.basicConfig(level=logging.DEBUG, format=log_format) logging.basicConfig(level=logging.DEBUG, format=log_format)
base = os.path.dirname(os.path.abspath(__file__)) base = os.path.dirname(os.path.abspath(__file__))
os.chdir(base) os.chdir(base)
if args.lights:
time.sleep(5)
player = get_player(fullscreen=not args.window) player = get_player(fullscreen=not args.window)
server = ThreadingUDPServer(('0.0.0.0', args.port), Handler) server = ThreadingUDPServer(('0.0.0.0', args.port), Handler)
server.player = Player(peer, player, args.playlist, args.prefix, args.lights) server.player = Player(peer, player, args.playlist, args.prefix)
player.register_key_binding('q', server.q_binding) player.register_key_binding('q', server.q_binding)
logger.debug("listen on %s...", args.port) logger.debug("listen on %s...", args.port)

View file

@ -92,3 +92,8 @@ def update_playlist(playlist, prefix, position=None, shift=True):
def trigger_lights(path): def trigger_lights(path):
cmd = ['python3', '-m', 'cdoseaplay.lights', path] cmd = ['python3', '-m', 'cdoseaplay.lights', path]
subprocess.Popen(cmd) subprocess.Popen(cmd)
def get_path(path):
if isinstance(path, bytes):
path = path.decode()
return path