simplified external audio loading

This commit is contained in:
Christoph Stahl 2024-10-10 09:53:41 +02:00
parent 63555dde87
commit f446733bb2
2 changed files with 5 additions and 4 deletions

View file

@ -91,10 +91,10 @@ class Player:
loop = asyncio.get_running_loop() loop = asyncio.get_running_loop()
self.mpv.pause = True self.mpv.pause = True
self.mpv.play(video)
await loop.run_in_executor(None, self.mpv.wait_for_event, "file-loaded")
if audio: if audio:
self.mpv.audio_add(audio) self.mpv.loadfile(video, audio_file=audio)
else:
self.mpv.loadfile(video)
self.mpv.pause = False self.mpv.pause = False
await loop.run_in_executor(None, self.mpv.wait_for_property, "eof-reached") await loop.run_in_executor(None, self.mpv.wait_for_property, "eof-reached")
self.mpv.play(f"{__dirname__}/static/background.png") self.mpv.play(f"{__dirname__}/static/background.png")

View file

@ -1,4 +1,4 @@
from typing import Any, Callable, Iterable, Protocol from typing import Any, Callable, Iterable, Optional, Protocol
from PIL.Image import Image from PIL.Image import Image
@ -34,5 +34,6 @@ class MPV:
def create_image_overlay(self, image: Image, pos: tuple[int, int]) -> ImageOverlay: ... def create_image_overlay(self, image: Image, pos: tuple[int, int]) -> ImageOverlay: ...
def remove_overlay(self, overlay_id: int) -> None: ... def remove_overlay(self, overlay_id: int) -> None: ...
def observe_property(self, property: str, callback: Callable[[str, Any], None]) -> None: ... def observe_property(self, property: str, callback: Callable[[str, Any], None]) -> None: ...
def loadfile(self, file: str, audio_file: Optional[str] = None) -> None: ...
def __setitem__(self, key: str, value: str) -> None: ... def __setitem__(self, key: str, value: str) -> None: ...
def __getitem__(self, key: str) -> str: ... def __getitem__(self, key: str) -> str: ...