Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_transfer_voice.py @ 491:203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:44:32 +0200 |
parents | 3c9ba4a694ef |
children |
comparison
equal
deleted
inserted
replaced
490:962d17c4078c | 491:203755bbe0fe |
---|---|
54 self._play_timer = None | 54 self._play_timer = None |
55 self.record_time = None | 55 self.record_time = None |
56 self.audio = audio | 56 self.audio = audio |
57 self.audio.file_path = "/sdcard/cagou_record.3gp" | 57 self.audio.file_path = "/sdcard/cagou_record.3gp" |
58 | 58 |
59 def _updateTimer(self, dt): | 59 def _update_timer(self, dt): |
60 self.time = int(time.time() - self._started_at) | 60 self.time = int(time.time() - self._started_at) |
61 | 61 |
62 def switchRecording(self): | 62 def switch_recording(self): |
63 if self.playing: | 63 if self.playing: |
64 self._stopPlaying() | 64 self._stop_playing() |
65 if self.recording: | 65 if self.recording: |
66 try: | 66 try: |
67 audio.stop() | 67 audio.stop() |
68 except Exception as e: | 68 except Exception as e: |
69 # an exception can happen if record is pressed | 69 # an exception can happen if record is pressed |
73 self.time = self.time + 1 | 73 self.time = self.time + 1 |
74 else: | 74 else: |
75 audio.start() | 75 audio.start() |
76 self._started_at = time.time() | 76 self._started_at = time.time() |
77 self.time = 0 | 77 self.time = 0 |
78 self._counter_timer = Clock.schedule_interval(self._updateTimer, 1) | 78 self._counter_timer = Clock.schedule_interval(self._update_timer, 1) |
79 | 79 |
80 self.recording = not self.recording | 80 self.recording = not self.recording |
81 | 81 |
82 def _stopPlaying(self, __=None): | 82 def _stop_playing(self, __=None): |
83 if self.record_time is None: | 83 if self.record_time is None: |
84 log.error("_stopPlaying should no be called when record_time is None") | 84 log.error("_stop_playing should no be called when record_time is None") |
85 return | 85 return |
86 audio.stop() | 86 audio.stop() |
87 self.playing = False | 87 self.playing = False |
88 self.time = self.record_time | 88 self.time = self.record_time |
89 if self._counter_timer is not None: | 89 if self._counter_timer is not None: |
90 self._counter_timer.cancel() | 90 self._counter_timer.cancel() |
91 | 91 |
92 def playRecord(self): | 92 def play_record(self): |
93 if self.recording: | 93 if self.recording: |
94 return | 94 return |
95 if self.playing: | 95 if self.playing: |
96 self._stopPlaying() | 96 self._stop_playing() |
97 else: | 97 else: |
98 try: | 98 try: |
99 audio.play() | 99 audio.play() |
100 except Exception as e: | 100 except Exception as e: |
101 # an exception can happen in the same situation | 101 # an exception can happen in the same situation |
104 self.time = 0 | 104 self.time = 0 |
105 return | 105 return |
106 | 106 |
107 self.playing = True | 107 self.playing = True |
108 self.record_time = self.time | 108 self.record_time = self.time |
109 Clock.schedule_once(self._stopPlaying, self.time + 1) | 109 Clock.schedule_once(self._stop_playing, self.time + 1) |
110 self._started_at = time.time() | 110 self._started_at = time.time() |
111 self.time = 0 | 111 self.time = 0 |
112 self._counter_timer = Clock.schedule_interval(self._updateTimer, 0.5) | 112 self._counter_timer = Clock.schedule_interval(self._update_timer, 0.5) |