Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Feature: App play recording functionality (#65)
Browse files Browse the repository at this point in the history
* Add replay recording functionality

* Add dependencies for kivy video player
  • Loading branch information
OskarSoderberg authored Aug 22, 2022
1 parent b3321ff commit 3b326b2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,28 @@
"Docstrings",
"dotenv",
"gazedata",
"halign",
"isort",
"keepalive",
"kivy",
"pylib",
"pyright",
"pytest",
"PYTHONDEVMODE",
"recycleboxlayout",
"recycleview",
"rtsp",
"scenecamera",
"scenevideo",
"screenmanager",
"selectables",
"setuptools",
"subprotocol",
"subprotocols",
"tobii",
"unsubscription",
"videoplayer",
"viewclass",
"websockets",
"zeroconf"
],
Expand Down
54 changes: 42 additions & 12 deletions examples/g3pycontroller/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
id: sm
transition: NoTransition()
<RecordingScreen>:
VideoPlayer:
id: videoplayer
<RecorderScreen>:
BoxLayout:
BoxLayout:
Expand All @@ -105,6 +109,9 @@
Button:
text: "Delete"
on_press: app.send_control_event(ControlEventKind.DELETE_RECORDING)
Button:
text: "Play"
on_press: app.send_control_event(ControlEventKind.PLAY_RECORDING)
SelectableList:
id: recordings
Expand Down Expand Up @@ -183,7 +190,7 @@ def add_service(
self, hostname: str, ipv4: Optional[str], ipv6: Optional[str]
) -> None:
self.ids.services.data.append(
{"id": hostname, "text": f"{hostname}\n{ipv4}\n{ipv6}"}
{"hostname": hostname, "text": f"{hostname}\n{ipv4}\n{ipv6}"}
)
logging.info(f"Services: Added {hostname}, {ipv4}, {ipv6}")

Expand All @@ -192,7 +199,7 @@ def update_service(
) -> None:
services = self.ids.services
for service in services.data:
if service["id"] == hostname:
if service["hostname"] == hostname:
service["text"] = f"{hostname}\n{ipv4}\n{ipv6}"
logging.info(f"Services: Updated {hostname}, {ipv4}, {ipv6}")

Expand All @@ -201,7 +208,7 @@ def remove_service(
) -> None:
services = self.ids.services
services.data = [
service for service in services.data if service["id"] != hostname
service for service in services.data if service["hostname"] != hostname
]
logging.info(f"Services: Removed {hostname}, {ipv4}, {ipv6}")

Expand All @@ -214,6 +221,7 @@ class ControlScreen(Screen):
def __init__(self, **kw):
super().__init__(**kw)
self.ids.sm.add_widget(RecorderScreen(name="recorder"))
self.ids.sm.add_widget(RecordingScreen(name="recording"))
self.ids.sm.add_widget(LiveScreen(name="live"))

def clear(self) -> None:
Expand All @@ -222,6 +230,8 @@ def clear(self) -> None:

def switch_to_screen(self, screen: str) -> None:
self.ids.sm.current = screen
if self.ids.sm.current == "recording":
self.ids.sm.get_screen("recording").ids.videoplayer.state = "stop"

def set_task_running_status(self, is_running: bool) -> None:
if is_running:
Expand All @@ -233,6 +243,10 @@ def set_hostname(self, hostname: str) -> None:
self.ids.hostname.text = hostname


class RecordingScreen(Screen):
pass


class RecorderScreen(Screen):
def add_recording(
self, visible_name: str, uuid: str, recording: Recording, atEnd: bool = False
Expand Down Expand Up @@ -306,7 +320,9 @@ def start_control(self) -> bool:
popup.open()
return False
else:
hostname = self.get_screen("discovery").ids.services.data[selected[0]]["id"]
hostname = self.get_screen("discovery").ids.services.data[selected[0]][
"hostname"
]
self.backend_control_task = self.create_task(
self.backend_control(hostname), name="backend_control"
)
Expand Down Expand Up @@ -412,6 +428,8 @@ async def handle_control_event(self, g3: Glasses3, event: ControlEventKind) -> N
self.start_live_stream(g3)
case ControlEventKind.STOP_LIVE:
await self.stop_live_stream()
case ControlEventKind.PLAY_RECORDING:
await self.play_selected_recording(g3)
self.get_screen("control").set_task_running_status(False)

def start_live_stream(self, g3: Glasses3) -> None:
Expand Down Expand Up @@ -483,22 +501,34 @@ async def stop_live_stream(self) -> None:
Window.unbind(on_resize=live_screen.clear)
live_screen.clear()

async def delete_selected_recording(self, g3: Glasses3) -> None:
selected = (
self.get_screen("control")
.ids.sm.get_screen("recorder")
.ids.recordings.ids.selectables.selected_nodes
def get_selected_recording(self) -> Optional[str]:
recordings = (
self.get_screen("control").ids.sm.get_screen("recorder").ids.recordings
)
selected = recordings.ids.selectables.selected_nodes
if len(selected) != 1:
popup = UserMessagePopup(title="No recording selected")
popup.ids.message_label.text = "Please select a recording and try again."
popup.open()
else:
uuid = (
return recordings.data[selected[0]]["uuid"]

async def play_selected_recording(self, g3: Glasses3) -> None:
uuid = self.get_selected_recording()
if uuid is not None:
self.get_screen("control").switch_to_screen("recording")
file_url = await g3.recordings.get_recording(uuid).get_scenevideo_url()
videoplayer = (
self.get_screen("control")
.ids.sm.get_screen("recorder")
.ids.recordings.data[selected[0]]["uuid"]
.ids.sm.get_screen("recording")
.ids.videoplayer
)
videoplayer.source = file_url
videoplayer.state = "play"

async def delete_selected_recording(self, g3: Glasses3) -> None:
uuid = self.get_selected_recording()
if uuid is not None:
await g3.recordings.delete(uuid)

async def update_recordings(self, g3, recordings_events):
Expand Down
1 change: 1 addition & 0 deletions examples/g3pycontroller/eventkinds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ControlEventKind(Enum):
DELETE_RECORDING = auto()
START_LIVE = auto()
STOP_LIVE = auto()
PLAY_RECORDING = auto()


class AppEventKind(Enum):
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ examples = [
"python-dotenv",
"opencv-python"
]
example-app = ["kivy ~= 2.1.0"]
example-app = [
"kivy[media] ~= 2.1.0"
]

[project.urls]
Home = "https://github.com/tobiipro/g3pylib"
Expand Down
2 changes: 1 addition & 1 deletion requirements-examples.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r requirements.txt
python-dotenv
opencv-python
kivy ~= 2.1.0
kivy[media] ~= 2.1.0

0 comments on commit 3b326b2

Please sign in to comment.