MCPcopy Create free account
hub / github.com/pyscript/pyscript / SoundPlayer

Class SoundPlayer

core/tests/manual/issue-2302/libthree.py:14–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13@dataclass
14class SoundPlayer:
15 sound: THREE.Audio = field()
16 on_start: Callable[[], None] = field()
17 on_stop: Callable[[], None] = field(default=lambda: None)
18
19 _start_time: float = -1.0
20
21 def play(self):
22 self.sound.stop()
23 self.on_start()
24 self._start_time = self.sound.context.currentTime
25 self.sound.play()
26
27 def stop(self):
28 self.sound.stop()
29 self.on_stop()
30 self._start_time = -1.0
31
32 def toggle(self):
33 if self.sound.isPlaying:
34 self.stop()
35 else:
36 self.play()
37
38 @property
39 def running_time(self):
40 if self.sound.isPlaying:
41 return self.sound.context.currentTime - self._start_time
42 elif self._start_time != -1.0:
43 self.stop()
44 return 0.0
45
46def get_renderer():
47 renderer = new(THREE.WebGLRenderer, antialias=True)

Callers 1

main.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected