gutted seek function; addressed initial walk issues
This commit is contained in:
+40
-24
@@ -148,6 +148,8 @@ class NaoMusicPlayer:
|
||||
self.current_task_id = None
|
||||
self.is_playing = False
|
||||
self.paused_position = 0.0
|
||||
self.play_start_time = None
|
||||
self.position_at_start = 0.0
|
||||
self.current_title = ""
|
||||
self.is_loading = False
|
||||
self.load_error = None
|
||||
@@ -180,6 +182,12 @@ class NaoMusicPlayer:
|
||||
|
||||
_DL_PROGRESS_RE = re.compile(r'\[download\]\s+([\d.]+)%')
|
||||
|
||||
def _current_position(self):
|
||||
"""Playback position tracked client-side, independent of NAOqi's getCurrentPosition."""
|
||||
if self.is_playing and self.play_start_time is not None:
|
||||
return self.position_at_start + (time.time() - self.play_start_time)
|
||||
return self.paused_position
|
||||
|
||||
def play(self, url, title):
|
||||
self.stop()
|
||||
self.current_title = title
|
||||
@@ -252,6 +260,9 @@ class NaoMusicPlayer:
|
||||
self.progress = 100.0
|
||||
self.current_task_id = self.player.playFile(self.remote_path)
|
||||
self.is_playing = True
|
||||
self.play_start_time = time.time()
|
||||
self.position_at_start = 0.0
|
||||
self.paused_position = 0.0
|
||||
print(f"♪ Playing on NAO: {title} (task {self.current_task_id})")
|
||||
return True
|
||||
except Exception as e:
|
||||
@@ -265,22 +276,30 @@ class NaoMusicPlayer:
|
||||
if self.current_task_id is None or not self.current_file:
|
||||
print("⏸ Nothing loaded to pause/resume")
|
||||
return
|
||||
try:
|
||||
if self.is_playing:
|
||||
pos = self.player.getCurrentPosition(self.current_task_id)
|
||||
if self.is_playing:
|
||||
pos = self._current_position()
|
||||
try:
|
||||
self.player.stopAll()
|
||||
self.paused_position = max(0.0, pos)
|
||||
self.is_playing = False
|
||||
print(f"♪ Paused at {self.paused_position:.1f}s")
|
||||
else:
|
||||
except Exception as e:
|
||||
print(f"stopAll error while pausing: {e}")
|
||||
self.load_error = f"Pause error: {e}"
|
||||
return
|
||||
self.paused_position = max(0.0, pos)
|
||||
self.is_playing = False
|
||||
self.play_start_time = None
|
||||
print(f"♪ Paused at {self.paused_position:.1f}s")
|
||||
else:
|
||||
try:
|
||||
self.current_task_id = self.player.playFileFromPosition(
|
||||
self.current_file, self.paused_position, 1.0, 0.0
|
||||
)
|
||||
self.is_playing = True
|
||||
self.play_start_time = time.time()
|
||||
self.position_at_start = self.paused_position
|
||||
print(f"♪ Resumed from {self.paused_position:.1f}s (task {self.current_task_id})")
|
||||
except Exception as e:
|
||||
print(f"Pause/resume error: {e}")
|
||||
self.load_error = f"Pause error: {e}"
|
||||
except Exception as e:
|
||||
print(f"Resume error: {e}")
|
||||
self.load_error = f"Resume error: {e}"
|
||||
|
||||
def stop(self):
|
||||
try:
|
||||
@@ -290,16 +309,10 @@ class NaoMusicPlayer:
|
||||
self.is_playing = False
|
||||
self.current_file = None
|
||||
self.current_task_id = None
|
||||
self.current_title = ""
|
||||
self.paused_position = 0.0
|
||||
|
||||
def seek(self, seconds):
|
||||
if self.current_task_id is None:
|
||||
return
|
||||
try:
|
||||
pos = self.player.getCurrentPosition(self.current_task_id)
|
||||
self.player.goTo(self.current_task_id, max(0.0, pos + seconds))
|
||||
except Exception as e:
|
||||
print(f"Seek error: {e}")
|
||||
self.play_start_time = None
|
||||
self.position_at_start = 0.0
|
||||
|
||||
|
||||
# ==========================================
|
||||
@@ -469,9 +482,16 @@ class NaoTeleop:
|
||||
time.sleep(1.0)
|
||||
self.motion.setMoveArmsEnabled(True, True)
|
||||
|
||||
print("🦶 Initializing walk engine...")
|
||||
try:
|
||||
self.motion.moveInit()
|
||||
except Exception as e:
|
||||
print(f"moveInit error: {e}")
|
||||
print("🦶 Walk engine ready")
|
||||
|
||||
carpet_config = [["StepHeight", 0.028], ["MaxStepFrequency", 0.6], ["TorsoWy", 0.05]]
|
||||
|
||||
print("\n🎮 Controls: WASD/Arrows=Walk | IJKL=Head | SPACE=Reset head | 1=Wave | M=Music search (↑↓ select, Enter confirm) | P=Pause | X=Stop | ,/.=Seek | -/==Volume | T=TTS | ESC=Quit")
|
||||
print("\n🎮 Controls: WASD/Arrows=Walk | IJKL=Head | SPACE=Reset head | 1=Wave | M=Music search (↑↓ select, Enter confirm) | P=Pause | X=Stop | -/==Volume | T=TTS | ESC=Quit")
|
||||
|
||||
try:
|
||||
while self.running:
|
||||
@@ -559,10 +579,6 @@ class NaoTeleop:
|
||||
self.music.pause()
|
||||
elif event.key == pygame.K_x:
|
||||
self.music.stop()
|
||||
elif event.key == pygame.K_COMMA:
|
||||
self.music.seek(-10)
|
||||
elif event.key == pygame.K_PERIOD:
|
||||
self.music.seek(10)
|
||||
elif event.key in (pygame.K_MINUS, pygame.K_KP_MINUS):
|
||||
self.change_volume(-5)
|
||||
elif event.key in (pygame.K_EQUALS, pygame.K_KP_PLUS):
|
||||
|
||||
Reference in New Issue
Block a user